我有這種奇怪的行爲,我無法找到解決方案... 這隻發生在我的模擬器API級別10,在我的智能手機(Android 4.1)上工作正常。Android:AnimationDrawable擠壓我的形象
我寫了一個動態動畫來展示一個滾動的骰子,其中10個隨機幀被選爲動畫的幀,持續時間爲50ms。
當我按下按鈕,動畫運行,但擠壓到零高度.....(你仍然可以看到動畫骰子的一些顏色),佈局也會搞砸。 雖然這不會發生在我的手機上。
這裏是Java代碼的所述部分:
public void RollDice(View view) {
int id=-1;
AnimationDrawable diceAnimation = new AnimationDrawable();
//create 10 random frames from dice1.jpg to dice6.jpg into diceAnimation
for(int j=0;j<10;j++){
id=getResources().getIdentifier("dice"+String.valueOf(rng.nextInt(6)+1), "drawable", getPackageName());
diceAnimation.addFrame(getResources().getDrawable(id), 50);
}
//assigning and starting animation
diceAnimation.setOneShot(true);
dice.setImageDrawable(diceAnimation);
diceAnimation.start();
}
和XML的部分:
<ImageView
android:id="@+id/Dice1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:contentDescription="@string/diceimage"
android:src="@drawable/dice1" />
按鈕的onclick調用RollDice()。
至於最後再說一句,如果我的ImageView硬編碼,說的android:layout_height = 「100dp」,那麼骰子動畫中顯示,但streched成有趣的形狀......
我試着大多數縮放方法,adjustviewbound等沒有運氣...
有幫助嗎? :( – Ivan