2012-10-09 15 views
0

我有一個動畫列表組成的(略)不同的大小。我有一個ImageViewlayout_widthlayout_height設置爲wrap_content。我設置了動畫列表是我ImageView的內容和如下啓動動畫:AnimationDrawable動畫列表與各種大小的drawables?

AnimationDrawable my_animation_list = (AnimationDrawable)getResources().getDrawable(
    R.drawable.my_animation_list); 

myImageView.setImageDrawable(my_animation_list) 
((AnimationDrawable)myImageView.getDrawable()).start(); 

我需要和期望的ImageView調整其高度和寬度與在動畫列表中的每個幀/圖像。相反,它看起來像是ImageView取得動畫列表中第一幀的高度和寬度,然後縮放動畫列表中的所有幀以適應此初始高度和寬度。任何人都知道我怎樣才能得到一個AnimationDrawable(動畫列表),包括各種尺寸圖像的與ImageView工作,或工作,甚至左右?..

回答

1

我到底做了什麼是創造我的AnimationDrawable從我animation-list和以前一樣,如下...

// declaration in activity 
private AnimationDrawable my_animation_list; 

// load animation list in onCreate() method of activity or elsewhere 
my_animation_list = (AnimationDrawable)getResources().getDrawable(
    R.drawable.my_animation_list); 

然而......,而不是分配此AnimationDrawableImageView,然後啓動它(在我的問題),我現在做的是在動畫列表框手動分配給我的ImageView,如下...

myImageView.setImageDrawable(my_animation_list.getFrame(myCurrentFrameIndex)); 
myCurrentFrameIndex++; 

...和我使用Handler發送/接收/處理連續Message實例來更新顯示的幀,確定每個幀的持續時間如下:

my_animation_list.getDuration(myCurrentFrameIndex); 
0

不是最有趣的事情,但你可以換你的位圖InsetDrawables,使他們相同的大小。修復它們自己的位圖可能更容易。我沒有看過的AnimationDrawable代碼,所以有可能是更好的辦法......