I want to animate four images to be displayed in a row. In the layout XML-file I'm creating an ImageView:
<ImageView
android:id="@+id/exercisesAnimated"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:adjustViewBounds="true"
android:layout_gravity="center_horizontal"/>
In my code I then create the AnimationDrawable
via
private void startAnimation() throws IOException {
AnimationDrawable animation = new AnimationDrawable();
String path = "Graphics/" + exercise.getName() + "/";
InputStream is = getAssets().open(path + "1.jpg");
animation.addFrame(Drawable.createFromStream(is, null), 800);
is = getAssets().open(path + "2.jpg");
animation.addFrame(Drawable.createFromStream(is, null), 800);
is = getAssets().open(path + "3.jpg");
animation.addFrame(Drawable.createFromStream(is, null), 800);
is = getAssets().open(path + "4.jpg");
animation.addFrame(Drawable.createFromStream(is, null), 800);
animation.setOneShot(false);
ImageView imageAnim = (ImageView) findViewById(R.id.exercisesAnimated);
imageAnim.setBackgroundDrawable(animation);
animation.start();
}
So my problem is that the animated images become really small, like 1/3 of the original size of the images. These have a size of 460x250, I want them to be shown in that size.
If I just put a android:src="@drawable/oneOfTheImages"
to the ImageView and dont do the animation the image is displayed in the correct size.
What's wrong?
try putting your jpg files in the res/drawable-nodpi folder and pull them as Drawables in the startAnimation method like this :
getResources().getDrawable(R.drawable.1) // this will pull the 1.jpg file and return a Drawable