【发布时间】:2013-09-27 18:39:19
【问题描述】:
我想为四个图像制作动画,使其连续显示。在布局 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"/>
然后在我的代码中创建AnimationDrawablevia
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 中而不做动画,则图像将以正确的大小显示。
怎么了?
【问题讨论】:
-
为什么要把你的 jpg 文件放在 assets 中?你为什么不简单地使用 res/drawable/ 文件夹?
-
我需要子文件夹,这在 res/drawable 中是不可能的。
标签: android imageview animationdrawable