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