我正在查看animation-list的文档,XML布局非常简单,但我很困惑他们在代码中如何处理它。如何使动画列表显示在屏幕上
在该网页,他们有这样的:
ImageView img = (ImageView)findViewById(R.id.spinning_wheel_image);
img.setBackgroundResource(R.drawable.spin_animation);
// Get the background, which has been compiled to an AnimationDrawable object.
AnimationDrawable frameAnimation = (AnimationDrawable) img.getBackground();
// Start the animation (looped playback by default).
frameAnimation.start();
但他们从来没有引用spinning_wheel_image在他们表现出任何地方的XML,也不spin_animation ....在他们的例子自旋片段中的ID是“选择“
所以我想知道这两个引用来自哪里?并且为什么从未使用过“被选中”的XML片段的实际ID?
谢谢!
编辑:
我把我的动画XML到一个名为animation.xml
并在代码现在我有这样的:
ImageView img = (ImageView)findViewById(R.id.spinning_wheel_image);
img.setBackgroundResource(R.drawable.animation);
// Get the background, which has been compiled to an AnimationDrawable object.
AnimationDrawable frameAnimation = (AnimationDrawable) img.getBackground();
// Start the animation (looped playback by default).
frameAnimation.start();