Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>Here is one way to implement your own AnimationListener</p> <pre><code>package com.example.intentfiletersample; 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 &amp;&amp; mBreakDelay &gt; 0 ? mBreakDelay : mDuration ); } public static interface AnimationListener { public void onAnimationEnd(); // You can add onAnimationStart(), and do the same thing like onAnimationEnd. } }; </code></pre> <p>It is always recommended that you first go through the Animation API comes with Android sdk, see if one that fits you before implementing your own. </p> <p>HOPE THIS HELP.</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload