如何使 ImageView 仅对动画使用特定的可绘制对象,然后在动画完成后恢复到之前的可绘制对象。我的尝试如下,但它不起作用,因为它在动画期间从未显示“alt_die_”可绘制对象。在动画期间和之后显示的唯一可绘制对象是常规的“die_”可绘制对象。注意:我是 android studios 的新手,所以如果我没有使用正确的术语,我很抱歉。
String result;
AnimationSet down_rotate = new AnimationSet(false);
AnimationSet up_rotate = new AnimationSet(false);
// Fill the dice widgets with the images to be show during animation
for (int index = 0; index < 3; index++) {
String image_name = "alt_die_" + dice_values.get(index) + ".png";
try {
InputStream stream = getAssets().open(image_name);
Drawable d = Drawable.createFromStream(stream, null);
dice_images.get(index).setImageDrawable(d);
} catch (IOException e) {
e.printStackTrace();
}
}
// Animate the dice by rolling and bouncing the dice
down_rotate.addAnimation (bounce_down());
down_rotate.addAnimation (rotate());
die_image_3.startAnimation(down_rotate);
die_image_2.startAnimation(down_rotate);
up_rotate.addAnimation (bounce_up());
up_rotate.addAnimation (rotate());
die_image_1.startAnimation(up_rotate);
// Fill the dice widgets with the images to be shown after the animation
for (int index = 0; index < 3; index++) {
String image_name = "die_" + dice_values.get(index) + ".png";
try {
InputStream stream = getAssets().open(image_name);
Drawable d = Drawable.createFromStream(stream, null);
dice_images.get(index).setImageDrawable(d);
} catch (IOException e) {
e.printStackTrace();
}
}
最佳答案
我无法在移动设备上格式化代码,但我有一个想法,
将上面代码中的第一个循环放在方法中,例如
Public void showDefaultDrawable () {
for () {
show alt_die
}
}
在第二个循环中创建一个 if 来捕获循环的结尾并调用 showDefaultDrawable 方法,例如
for () {
show die
if (index == 3) {
showDefaultDrawable ();
}
}
然后你可以在需要的时候调用默认方法
关于java - 如何仅在带有 ImageView 小部件的 xml 动画期间使用不同的可绘制对象 (android),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44619514/