0

我正在尝试使用 xml objectAnimator 创建翻译图像(球)。当我尝试引用我的 objectAnimator xml 文件时,它说 getApplicationContext() 可能返回 null。当我把它刷到我的手机上时,它立即崩溃了。当我取出那条线和 setAnimationListener 线时,它就起作用了。但是,如果只有其中一条线,它就不起作用。

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);
}
}

移动.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>

任何帮助将非常感激。

4

1 回答 1

1

AnimationUtils:createAnimationFromXml

第 112 - 125 行 android 不支持“objectAnimator”

也许你需要的是 AnimatorInflater.loadAnimator

于 2014-04-07T10:02:09.767 回答