2

I was wondering why my animated gif is not displaying properly and whether anyone can suggest what I have done wrong.

here is the code :

<animation-list xmlns:android="http://schemas.android.com/apk/res/android" >

<item android:drawable="@drawable/star1" android:duration="500" />
<item android:drawable="@drawable/star2" android:duration="500" />
<item android:drawable="@drawable/star3" android:duration="500" />
<item android:drawable="@drawable/star4" android:duration="500" />
<item android:drawable="@drawable/star5" android:duration="500" />
<item android:drawable="@drawable/star6" android:duration="500" />

</animation-list>

I set the duration long so I can see what was going on and why it looked wrong ....

image view in layout xml of a dialog box

<ImageView
    android:id="@+id/image"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_marginRight="5dp"
     />

here is the java to load it :

    ImageView img = (ImageView) dialog.findViewById(R.id.image);
     img.setBackgroundResource(R.drawable.star_animation);
     AnimationDrawable frameAnimation = (AnimationDrawable) img.getBackground();
     frameAnimation.start();

The animation loads and works fine except 1 image in the sequence messes up ... here is a screen of the png :

enter image description here

star4.png appears to stretch the image and I don't know why.... anyone got an ideas... I have tried making the image same size as star1 with transparency but that also did not work....

I remade image star4.png with a larger transparent area.... this appears to have worked. I don't think it worked when I tried above as I didn't clean the project before running.

Cheers Guys

Xeo
  • 389
  • 1
  • 5
  • 13
  • Is your `AnimationDrawable` within your onCreate method? – u3l Feb 27 '14 at 11:52
  • The problem is with your `star4.png` image. Crop the `star4.png` and remove the white space (width wise). – Joel Fernandes Feb 27 '14 at 11:55
  • No it is within a sequence of events that is called when a game finishes and displays a dialog and I wanted this in the dialog popup. – Xeo Feb 27 '14 at 11:56
  • 1
    You are sing your anmation as a BACKGROUND (which stretches images). Look at [this](http://stackoverflow.com/questions/2785336/starting-frame-by-frame-animation) – Phantômaxx Feb 27 '14 at 11:59
  • there is no white space that is only there cos it was taken from screen shot in file explorer.... It doesn't stretch the other images though ? ... I set it as a background image because that's what the android developer site kinda suggested .... I will look at that link. thanks – Xeo Feb 27 '14 at 12:07

0 Answers0