java - Android 对象动画 xml

标签 java android xml android-animation objectanimator

我正在尝试使用 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/

相关文章:

xml - 打开大型 xml 文件时 Eclipse galileo 挂起

java - synchronized block 是如何实现同步的

java - 在 Java 中生成所有排列

java - 斯卡拉。 float 的奇怪结果

android - 如何使用机器学习存储加速度计数据以进行分类

java - 为什么此 XQuery 查询找不到关键字的任何节点?

java - jaxb:如何绑定(bind)嵌套元素

java - 大黄蜂Q : Core API Producer and Asynchronous Consumer problems

android - Clean Architecture 和 Paging 3.0 with Room

java - 在 Activity 中设置计时器的最有效方法