I am trying to create translate a image (ball) using the xml objectAnimator. When I try to reference my objectAnimator xml file, it says getApplicationContext() might return null. When I flash it to my phone, it crashed immediately. When I take out that line and the setAnimationListener line, it works. However, if there is just one of those lines, it does not work.

MainActivity.java

public class MainActivity extends ActionBarActivity implements
Animation.AnimationListener{

ImageView ball;
Button moveb1;

Animation move;

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);

    ball = (ImageView) findViewById(R.id.ball);
    moveb1 = (Button) findViewById(R.id.move1);

    move = AnimationUtils.loadAnimation(getApplicationContext(),
            R.animator.move);

    move.setAnimationListener(this);
}
}

move.xml

<set xmlns:android="http://schemas.android.com/apk/res/android"
android:ordering="together">
<objectAnimator
    android:propertyName="x"
    android:duration="500"
    android:valueTo="400"
    android:valueType="intType"/>
<objectAnimator
    android:propertyName="y"
    android:duration="500"
    android:valueTo="300"
    android:valueType="intType"/>
</set>

Any help would be much appreciated.

有帮助吗?

解决方案

AnimationUtils:createAnimationFromXml

line 112 - 125 android have not support "objectAnimator"

maybe you need is AnimatorInflater.loadAnimator

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top