KB-20071208-025
From Triled Wiki
- Status: respond received
- author: amar9876
- link: http://groups.google.com/group/android-developers/msg/fb5728e1a713f88f
- Description: Impossible to view animation for animated GIFs.
- Steps to reproduce:
Write in layout file (example from amar9876 post):
<ImageView id="@+id/iv"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="@drawable/logo"
/>
If logo is animated gif - you'll not get animation.
[edit] Temporarily solution
Use AnimationDrawable to draw sequences of files.
Sample layout from Android SDK documentation:
<!-- Animation frames are wheel0.png -- wheel5.png files inside the res/drawable/ folder -->
<frames id="selected" oneshot="false">
<frame drawable="@drawable/wheel0" duration="50" />
<frame drawable="@drawable/wheel1" duration="50" />
<frame drawable="@drawable/wheel2" duration="50" />
<frame drawable="@drawable/wheel3" duration="50" />
<frame drawable="@drawable/wheel4" duration="50" />
<frame drawable="@drawable/wheel5" duration="50" />
</frames>
Sample code to handle this layout:
// Load the ImageView that will host the animation and
// set its background to our AnimationDrawable XML resource.
ImageView img = (ImageView)findViewById(R.id.spinning_wheel_image);
img.setBackground(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()
[edit] See also
- KB-20071207-026 - animated GIFs are not supported by Android browser.
