java - Frame Animation Not Running -
i have tried every sample of code can find defines , runs frame animation, imageview never changes. original image in imageview stays.
edit: after many days of trial , error, ran apk on phone instead of emulator. works on phone, reason not on emulator.
i not clear why can't start animations oncreate thread, need posted whatever thread handler of view created on.
@override public void oncreate(bundle savedinstancestate) { super.oncreate(savedinstancestate); setcontentview(r.layout.main); final imageview view = (imageview) findviewbyid(r.id.shell); view.setvisibility(imageview.visible); view.setbackgroundresource(r.drawable.animation_frame); view.post(new runnable(){ public void run(){ animationdrawable frameanimation = (animationdrawable) view.getbackground(); frameanimation.start(); } }); } }
i have no idea why need do.
edit:here snippets working project should need...
in java in oncreate:
final imageview image1 = (imageview) v.findviewbyid(r.id.coin1); image1.post(new runnable() { @override public void run() { animationdrawable ani = (animationdrawable) image1.getbackground(); ani.start(); } });
in xml layout:
<imageview android:layout_width="wrap_content" android:layout_height="wrap_content" android:background="@drawable/coin" android:id="@+id/coin1"/>
coin xml:
<animation-list xmlns:android="http://schemas.android.com/apk/res/android" android:oneshot="false"> <item android:drawable="@drawable/coin_spin_a" android:duration="100"/> <item android:drawable="@drawable/coin_spin_b" android:duration="100"/> <item android:drawable="@drawable/coin_spin_c" android:duration="100"/> <item android:drawable="@drawable/coin_spin_d" android:duration="100"/> <item android:drawable="@drawable/coin_spin_e" android:duration="100"/> <item android:drawable="@drawable/coin_spin_f" android:duration="100"/> </animation-list>
Comments
Post a Comment