我正在尝试使用 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>
任何帮助将不胜感激。
最佳答案
AnimationUtils:createAnimationFromXml
第 112 - 125 行 android 不支持“objectAnimator”
也许你需要的是AnimatorInflater.loadAnimator
关于java - Android 对象动画 xml,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22898283/