2011-09-15 9 views
0

ゲームプロジェクトでRotateAnimationTranslateAnimationを使用しています。回転を完了した後、TranslateAnimationを使用してイメージを次に保存します。それは正常に動作しますが、画像の回転が完了すると、一度画像が点滅します。アンドロイドのアニメーション?

public void Trainplace(int x,int y,Bitmap b){ 
    param.setMargins(x, y, 0, 0); 
    Train.setLayoutParams(param); 
    Train.setImageBitmap(b); 
    Train.setVisibility(0); 
} 
public void Trainmove(int x){ 
    TAnimation=new TranslateAnimation(0, 0, 0,x); 
    TAnimation.setInterpolator(new LinearInterpolator()); 
    TAnimation.setDuration(2000); 
    TAnimation.setFillAfter(true); 
    //TAnimation.setFillBefore(true); 
    Train.startAnimation(TAnimation); 
} 
public void Trainrotate(int a,int b,int c,int d){ 

    RAnimation=new RotateAnimation(a,b,c,d); 
    RAnimation.setInterpolator(new LinearInterpolator()); 
    RAnimation.setDuration(2000); 
    RAnimation.setFillAfter(true); 
    Train.startAnimation(RAnimation); 
} 

public void onClick(View v) { 
    switch (v.getId()) { 

    case R.id.b: 


     Trainplace(20, 255,bmpy1); 
     Trainrotate(0,90,50,25); 

     //Stop button clicks 
     //B.setEnabled(false); 

     break; 


    case R.id.b2: 
     Trainplace(35, 230,bmpx1); 
     Trainrotate(0,-90,20,-30); 

     RAnimation.setAnimationListener(new AnimationListener() { 


      public void onAnimationStart(Animation arg0) { 

      } 

      public void onAnimationRepeat(Animation arg0) { 

      } 


      public void onAnimationEnd(Animation arg0) { 

       int p=0; 
       while(p<=1){ 
       if(RAnimation.hasEnded()){ 
        Toast.makeText(getApplicationContext(), "End", Toast.LENGTH_SHORT).show(); 
       p=2; 
       } 
       } 


       Trainplace(85, 170,bmpy1); 

       Trainmove(-100); 
      } 
     }); 


     break; 

私の問題はrotateanimationを完了している - 現在の画像を別の画像に置き換えられます(。例:私の列車の画像は、IMがその場所に画像を90度回転を置き、その後90度回転)し、その後Translateanimationを使用することによって前進これは機能しています。

Rotateanimationを完了した後、Translateanimationを開始する前に、列車イメージが一度点滅します。

同じ画像は、問題なしで配置されます(アニメーションを回転に変換することを意味します)。

答えて

0

アニメーションが点滅すると、実際にアニメーションが実行される前に、アニメーションリスナーの 'onAnimationEnd'が発生している可能性が最も高いです。

avのカスタムビューまたはレイアウトを作成し、その 'animationEnd'メソッドを上書きしてリスナーを設定できるようにインターフェイスを追加できます。

はここ

CustomLayoutクラスは

public class CustomLayout extends LinearLayout { 
    private LayoutAnimationListener mListner; 

    public CustomLayout(Context context) { 
     super(context); 
    } 

    public CustomLayout(Context context, AttributeSet attrs) { 
     super(context, attrs); 
    } 

    @Override 
    protected void onAnimationEnd() { 
     super.onAnimationEnd(); 
     if(mListner != null){ 
      mListner.onAnimationEnd(CustomLayout.this); 
     } 
    } 

    @Override 
    protected void onAnimationStart() { 
     super.onAnimationStart(); 
     if(mListner != null){ 
      mListner.onAnimationStart(CustomLayout.this); 
     } 
    } 

    public static interface LayoutAnimationListener { 
     //Notifies the start of the animation. 
     void onAnimationStart(CustomLayout cLayout); 
     //Notifies the end of the animation. 
     void onAnimationEnd(CustomLayout cLayout); 
    } 

    public void setLayoutAnimationListener(LayoutAnimationListener listener){ 
     mListner = listener; 
    } 
} 

だからあなたの活動にあなたが通常のLinearLayoutとして使用することができますし、代わりにアニメーションにアニメーションリスナーを追加するのではレイアウトに追加することができます例ですlike

com.blessan.CustomLayout layout = 
      (com.blessan.CustomLayout)findViewById(R.id.counts_layout); 
    LayoutAnimationListener layoutAnimListener = new LayoutAnimationListener() {   
     @Override 
     public void onAnimationStart(CustomLayout cLayout) { 

     } 

     @Override 
     public void onAnimationEnd(CustomLayout cLayout) { 

     } 

    }; 
    layout.setLayoutAnimationListener(layoutAnimListener); 

これはあなたの役に立つかもしれません。試してみる。

+0

私の問題は、現在の画像を別の画像で置き換えた回転アニメーションをcopletingしていることです(例:私の列車の画像を90度回転させてから90度回転した画像をその場所に置いています)。そしてTranslateanimationを使って前進します。は働いている。私の問題は、Rotateanimationの完了後に画像を配置することです。そして、Translateanimationを開始する前に、列車の画像が一度点滅します。同じ画像は、noproblem(RotateanimationへのTranslateanimationを意味します)を置きます。私に答えてください.......... – venkat

関連する問題