2017-06-18 2 views
0

イメージビューでアニメーションに特定の描画可能オブジェクトを使用させ、アニメーションの終了後に元の描画可能状態に戻す方法を教えてください。私の試行は以下の通りで、アニメーション中に "alt_die_" drawableを表示しないため動作しません。アニメーション中およびアニメーション後に表示される唯一の描画可能なものは、通常の「die_」描画可能です。注:私はアンドロイドスタジオが初めてのため、適切な条件を使用しなかった場合は申し訳ありません。画像ビューウィジェット(アンドロイド)を使用したxmlアニメーションでのみ異なる描画機能を使用する方法

があれば作成する第二のループ内のメソッドなど

Public void showDefaultDrawable() { 

for() { 
show alt_die 
} 

} 

に上記のコード内で最初のループを入れ

 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(); 
      } 
     }    

答えて

0

私は携帯電話上のコードをフォーマットすることはできませんが、私はアイデアを持っています、 showDefaultDrawable方法例えばループの終わりをキャッチし、呼び出すことが

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

それから、いつでもデフォルトのメソッドを呼び出すことができます。

+0

2番目のループはアニメーションの後ですので、alt_dieを2回ロードするのはなぜですか? –

+0

いいえ、alt_dieを一度ロードするだけではなく、2番目のループのメソッドを作成したときに、最初のループが終了するまでそれを呼び出さないようにします。つまり、メソッドに入れたループを呼び出すことができます –

関連する問題