我有这种奇怪的行为,我无法找到解决方案... 这只发生在我的模拟器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