我想要將四個圖像設置爲連續顯示。在佈局XML文件,我創建的ImageView:AnimationDrawable縮小圖像以設置動畫
<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中,並且不執行動畫,圖像將以正確的大小顯示。
怎麼了?
爲什麼把你的JPG文件的資產?你爲什麼不簡單地使用res/drawable /文件夾? – Turkish
我需要子文件夾,這是res/drawable中不可能的。 – Syex