私は解決策を見つけることができないこの奇妙な動作をしています...これは私のスマートフォン(Android 4.1)のエミュレータAPIレベル10でのみ発生します。
ローリング サイコロを表示するダイナミック アニメーションを作成しました。アニメーションのフレームとして 10 個のランダム フレームが選択され、持続時間は 50 ミリ秒です。
ボタンを押すと、アニメーションが実行されますが、高さが 0 に絞られます..... (アニメーション サイコロからまだいくつかの色が表示されます)、レイアウトも台無しになります。これは私の電話では起こりません。
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" と言うと、サイコロはアニメーション中に表示されますが、面白い形に伸びます...
ほとんどのスケーリング方法、adjustviewboundなどを試しましたが、うまくいきませんでした...