0
@Override
 public void onCreate(Bundle savedInstanceState)
    {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.g_out);



        g = (ImageView)findViewById(R.id.gout);
        startService(new Intent(this, MyService2.class));



        SceneAnimation come = new SceneAnimation(g, out,duration);
        SceneAnimation circled = new SceneAnimation(g, circled,durationc);

       come.play(1);



       circled.play(1);









    }







}



class SceneAnimation {
public int x;
public ImageView mImageView;
public int[] mFrameRess;
public int[] mDurations;
public int mDuration;

public int mLastFrameNo;
public long mBreakDelay;



 public SceneAnimation(ImageView pImageView, int[] pFrameRess, int[] pDurations)
 {

    mImageView = pImageView;
    mFrameRess = pFrameRess;
    mDurations = pDurations;
    mLastFrameNo = pFrameRess.length - 1;

    play(1);
   }

    public SceneAnimation(ImageView pImageView, int[] pFrameRess, int pDuration){
    mImageView = pImageView;
    mFrameRess = pFrameRess;
    mDuration = pDuration;
    mLastFrameNo = pFrameRess.length - 1;

    mImageView.setImageResource(mFrameRess[0]);

    playConstant(1);
   }

    public SceneAnimation(ImageView pImageView, int[] pFrameRess, int pDuration, long pBreakDelay){            
    mImageView = pImageView;
    mFrameRess = pFrameRess;
    mDuration = pDuration;
    mLastFrameNo = pFrameRess.length - 1;
    mBreakDelay = pBreakDelay;

    mImageView.setImageResource(mFrameRess[0]);
    playConstant(1);
}


   public void play(final int pFrameNo)
{


    mImageView.postDelayed(new Runnable(){
        public void run() {


            mImageView.setImageResource(mFrameRess[pFrameNo]);
            if(pFrameNo == mLastFrameNo)
                {
                return;}
            else
                play(pFrameNo + 1);
        }
    }, mDurations[pFrameNo]);
}


public void playConstant(final int pFrameNo){
    mImageView.postDelayed(new Runnable(){
        public void run() {                    
            mImageView.setImageResource(mFrameRess[pFrameNo]);

            if(pFrameNo == mLastFrameNo)
                playConstant(0);
            else
                playConstant(pFrameNo + 1);
        }
    }, pFrameNo==mLastFrameNo && mBreakDelay>0 ? mBreakDelay : mDuration);
}



};

onCreate() で 2 つの SceneAnimation() を次々に再生するための解決策を探しています。それらは同時に再生され、一方が他方よりも長いため、2 番目が最初に再生され、次に最初のキックが開始されます。 2番目のフレームがそれ自体で終了するフレームで、AnimationListenerについて聞いたことがありますが、聞くクラスにそれを組み込む方法がわかりません。ウォークスルーまたはコード例と説明に感謝します。これは非常に初めてです。ありがとうあなたの時間のために

4

2 に答える 2

0
import android.widget.ImageView;

class SceneAnimation {
public int x;
public ImageView mImageView;
public int[] mFrameRess;
public int[] mDurations;
public int mDuration;

public int mLastFrameNo;
public long mBreakDelay;

private AnimationListener mAnimationListener;

public SceneAnimation( ImageView pImageView, int[] pFrameRess, int[] pDurations ) {

mImageView = pImageView;
mFrameRess = pFrameRess;
mDurations = pDurations;
mLastFrameNo = pFrameRess.length - 1;

play( 1 );
}

public SceneAnimation( ImageView pImageView, int[] pFrameRess, int pDuration ) {
mImageView = pImageView;
mFrameRess = pFrameRess;
mDuration = pDuration;
mLastFrameNo = pFrameRess.length - 1;

mImageView.setImageResource( mFrameRess[0] );

playConstant( 1 );
}

public SceneAnimation( ImageView pImageView, int[] pFrameRess, int pDuration, long     pBreakDelay ) {
mImageView = pImageView;
mFrameRess = pFrameRess;
mDuration = pDuration;
mLastFrameNo = pFrameRess.length - 1;
mBreakDelay = pBreakDelay;

mImageView.setImageResource( mFrameRess[0] );
playConstant( 1 );
}

public void setAnimationListener(AnimationListener listener){
this.mAnimationListener = listener;
}

public void play( final int pFrameNo ) {

mImageView.postDelayed( new Runnable() {
    public void run() {

        mImageView.setImageResource( mFrameRess[pFrameNo] );
        if ( pFrameNo == mLastFrameNo ) {
            return;
        } else
            play( pFrameNo + 1 );

        // Callback when animation ends.
        if( mAnimationListener != null ){
            mAnimationListener.onAnimationEnd();
        }
    }
}, mDurations[pFrameNo] );
}

public void playConstant( final int pFrameNo ) {
mImageView.postDelayed( new Runnable() {
    public void run() {
        mImageView.setImageResource( mFrameRess[pFrameNo] );

        if ( pFrameNo == mLastFrameNo )
            playConstant( 0 );
        else
            playConstant( pFrameNo + 1 );

        // Callback when animation ends.
        if( mAnimationListener != null ){
            mAnimationListener.onAnimationEnd();
        }
    }
}, pFrameNo == mLastFrameNo && mBreakDelay > 0 ? mBreakDelay : mDuration );
}


public static interface AnimationListener {
public void onAnimationEnd();
// You can add onAnimationStart(), and do the same thing like onAnimationEnd.
}
};
于 2012-11-19T03:39:42.383 に答える
0

実際、それは非常に簡単です。Animation インスタンスを作成し、それに AnimationListener をアタッチします。onAnimationEnd で、2 番目のアニメーションを開始します。出来上がり、順番に実行される 2 つのアニメーション。

    Animation firstAnimation = new TranslateAnimation(getApplicationContext(), null);
    firstAnimation.setAnimationListener(new Animation.AnimationListener() {

        @Override
        public void onAnimationStart(Animation animation) { 
        }

        @Override
        public void onAnimationRepeat(Animation animation) {
        }

        @Override
        public void onAnimationEnd(Animation animation) {
            Animation secondAnimation = new TranslateAnimation(getApplicationContext(), null);
            secondAnimation.start();
        }
    });

    firstAnimation.start();
于 2012-11-18T20:50:28.163 に答える