Java 如何仅在带有图像视图小部件(android)的xml动画期间使用不同的绘图

Java 如何仅在带有图像视图小部件(android)的xml动画期间使用不同的绘图,java,android,xml,animation,Java,Android,Xml,Animation,如何使图像视图仅对动画使用特定的可绘制图形,然后在动画完成后恢复到上一个可绘制图形。下面是我的尝试,它不起作用,因为它在动画中从不显示可绘制的“alt_die_”。在动画期间和之后显示的唯一可绘制图形是常规的“die_u2;”可绘制图形。注意:我是android工作室的新手,所以如果我没有使用正确的术语,我很抱歉 String result; AnimationSet down_rotate = new AnimationSet(false);

如何使图像视图仅对动画使用特定的可绘制图形,然后在动画完成后恢复到上一个可绘制图形。下面是我的尝试,它不起作用,因为它在动画中从不显示可绘制的“alt_die_”。在动画期间和之后显示的唯一可绘制图形是常规的“die_u2;”可绘制图形。注意:我是android工作室的新手,所以如果我没有使用正确的术语,我很抱歉

        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();
            }
        }            
字符串结果;
AnimationSet down_rotate=新的AnimationSet(假);
AnimationSet up\u rotate=新的AnimationSet(false);
//用动画期间要显示的图像填充骰子小部件
对于(int-index=0;index<3;index++){
字符串image_name=“alt_die_”+dice_values.get(index)+“.png”;
试一试{
InputStream=getAssets().open(图像名称);
Drawable d=Drawable.createFromStream(stream,null);
dice_images.get(index.setImageDrawable(d);
}捕获(IOE异常){
e、 printStackTrace();
}
}
//通过滚动和反弹骰子来设置骰子的动画
down_rotate.addAnimation(bounce_down());
down_rotate.addAnimation(rotate());
模具图像3.开始动画(向下旋转);
模具图像2.开始动画(向下旋转);
向上旋转.addAnimation(反弹向上());
up_rotate.addAnimation(rotate());
模具图像1.开始动画(向上旋转);
//用动画后显示的图像填充骰子小部件
对于(int-index=0;index<3;index++){
字符串image_name=“die_”+dice_values.get(index)+“.png”;
试一试{
InputStream=getAssets().open(图像名称);
Drawable d=Drawable.createFromStream(stream,null);
dice_images.get(index.setImageDrawable(d);
}捕获(IOE异常){
e、 printStackTrace();
}
}            

我不能在手机上格式化代码,但我有个主意

将上面代码中的第一个循环放在一个方法中,例如

Public void showDefaultDrawable () {

for () {
show alt_die
 }

 }
在第二个循环中,创建一个if来捕捉循环的结尾,并调用showDefaultDrawable方法,例如

for () {
show die
if (index == 3) {
showDefaultDrawable ();
}
}

然后你可以随时调用默认方法,我不能在手机上格式化代码,但我有个主意

将上面代码中的第一个循环放在一个方法中,例如

Public void showDefaultDrawable () {

for () {
show alt_die
 }

 }
在第二个循环中,创建一个if来捕捉循环的结尾,并调用showDefaultDrawable方法,例如

for () {
show die
if (index == 3) {
showDefaultDrawable ();
}
}

然后,您可以随时调用默认方法

第二个循环在动画之后,为什么我要加载alt_die两次?不,您只能加载alt_die一次,当你为第二个循环创建一个方法时,在第一个循环结束之前不要调用它,即index=3,然后你可以调用你放入方法中的循环第二个循环在动画之后,那么为什么我要加载alt_die两次呢?不,你只能加载alt_die一次,当您为第二个循环创建了一个方法时,在第一个循环结束之前不要调用它,即index=3,那么您可以调用您放入方法中的循环