我想为四个图像设置动画以连续显示。在布局 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,我希望它们以该尺寸显示。
如果我只是将 aandroid:src="@drawable/oneOfTheImages"
放到 ImageView 中而不做动画,则图像将以正确的大小显示。
怎么了?