1

I have rocket_thrust.xml in res/drawable/:

<animation-list xmlns:android="http://schemas.android.com/apk/res/android"
android:oneshot="false">
<item android:drawable="@drawable/r1" android:duration="200" />
<item android:drawable="@drawable/r2" android:duration="200" />
</animation-list>

And ImageView in res/layout/activity_main.xml

<ImageView
android:id="@+id/rocket_image"
android:orientation="vertical"
android:layout_alignParentBottom="true"
android:layout_width="fill_parent"
android:layout_height="wrap_content" >
</ImageView>

MainActivity.java

AnimationDrawable rocketAnimation;

public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);

ImageView rocketImage = (ImageView) findViewById(R.id.rocket_image);
rocketImage.setBackgroundResource(R.drawable.rocket_thrust);
rocketAnimation = (AnimationDrawable) rocketImage.getBackground();

showAnim();
}

public void showAnim() {
rocketAnimation.start();
}

This code is working.

But, the image is stretched. I don't want this stretching.

I changed:

rocketImage.setBackgroundResource(R.drawable.rocket_thrust);

with:

rocketImage.setImageResource(R.drawable.rocket_thrust);

for no stretching. The code is now not working.

How can I solve it?

ligi
  • 39,001
  • 44
  • 144
  • 244
Johnny
  • 612
  • 3
  • 13
  • 32

2 Answers2

1

I have it now.

 <LinearLayout
 android:id="@+id/layoutRocketL"
 android:orientation="vertical"
 android:layout_alignParentBottom="true"
 android:layout_width="fill_parent"
 android:layout_height="wrap_content"
 android:gravity="center" >
      <ImageView
      android:id="@+id/rocket_image"
      android:orientation="vertical"
      android:layout_alignParentBottom="true"
      android:layout_width="200dp"
      android:layout_height="wrap_content" >
      </ImageView>
 </LinearLayout>
Johnny
  • 612
  • 3
  • 13
  • 32
0
 imgMain.setImageResource(R.drawable.sh);

                imgMain.post(new Runnable() {

                    @Override
                    public void run() {
                        AnimationDrawable frameAnimation = (AnimationDrawable) imgMain.getDrawable();
                        frameAnimation.start();
                    }
                });



<ImageView
            android:id="@+id/imgMain"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:layout_gravity="center"
            android:scaleType="centerInside" />
Criss
  • 755
  • 7
  • 22