KB-20071208-025

From Triled Wiki

Jump to: navigation, search

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

Personal tools