Question

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.

Was it helpful?

Solution

AnimationUtils:createAnimationFromXml

line 112 - 125 android have not support "objectAnimator"

maybe you need is AnimatorInflater.loadAnimator

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top