Issue
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?
Solution
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>
Answered By - Johnny
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.