AnimationDrawable масштабирование изображений для анимации
Я хочу анимировать четыре изображения, которые будут отображаться подряд. В XML-файле макета я создаю ImageView:
<ImageView
android:id="@+id/exercisesAnimated"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:adjustViewBounds="true"
android:layout_gravity="center_horizontal"/>
В моем коде я создаю AnimationDrawable
с помощью
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();
}
Поэтому моя проблема в том, что анимированные изображения становятся очень маленькими, примерно 1/3 от исходного размера изображений. Они имеют размер 460x250, я хочу, чтобы они были показаны в этом размере.
Если я просто поставлю android:src="@drawable/oneOfTheImages"
в ImageView и не делайте анимацию, изображение отображается в правильном размере.
В чем дело?
1 ответ
Решение
Попробуйте поместить файлы jpg в папку res/drawable-nodpi и перетащите их как Drawables в метод startAnimation, например:
getResources().getDrawable(R.drawable.1) // this will pull the 1.jpg file and return a Drawable