1
我怎样才能从代码加载图像,动画,而不是从XML,我有这样的例子:的Android AnimationDrawable
<!-- Animation frames are wheel0.png -- wheel5.png files inside the
res/drawable/ folder -->
<animation-list android:id="@+id/selected" android:oneshot="false">
<item android:drawable="@drawable/wheel0" android:duration="50" />
<item android:drawable="@drawable/wheel1" android:duration="50" />
<item android:drawable="@drawable/wheel2" android:duration="50" />
<item android:drawable="@drawable/wheel3" android:duration="50" />
<item android:drawable="@drawable/wheel4" android:duration="50" />
<item android:drawable="@drawable/wheel5" android:duration="50" />
</animation-list>
的java文件:
ImageView img = (ImageView)findViewById(R.id.spinning_wheel_image);
img.setBackgroundResource(R.drawable.spin_animation);
AnimationDrawable frameAnimation = (AnimationDrawable) img.getBackground();
frameAnimation.start();
我需要加载相似图片:
for (int j = 0; j < 5; j++)
animation.addFrame(getResources().getDrawable(getResources().getIdentifier("wheel" + j,"drawable", getPackageName())), i);
我该如何结合?
什么阻止你创建一个'AnimationDrawable',然后在代码中添加像你的问题? – Luksprog 2013-03-04 11:43:38