2013-09-27 48 views
1

我想要將四個圖像設置爲連續顯示。在佈局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中,並且不執行動畫,圖像將以正確的大小顯示。

怎麼了?

+0

爲什麼把你的JPG文件的資產?你爲什麼不簡單地使用res/drawable /文件夾? – Turkish

+0

我需要子文件夾,這是res/drawable中不可能的。 – Syex

回答

2

嘗試把你的JPG文件在res /繪製-nodpi夾,並在startAnimation方法像這樣拉他們爲繪項目:

getResources().getDrawable(R.drawable.1) // this will pull the 1.jpg file and return a Drawable 
+1

謝謝,他們仍然不是原來的大小,但至少我現在可以縮放ImageView,所以我很好。 – Syex