android动画,当用户触摸图像时,它必须对gif文件进行动画处理
||
I \'M开发一个应用程序,在此当图像上用户触摸他会看到一个动画形象了一会儿,回来的原始图像。
I \'M能以动画GIF文件,但动画反复运行,如何限制动画,一旦动画完成,回来到图像视图
请任何人在这方面帮助我,
提前致谢
这是我的代码
package purpletalk.gifanimation;
import java.io.InputStream;
import android.app.Activity;
import android.content.Context;
import android.content.Intent;
import android.graphics.Canvas;
import android.graphics.Matrix;
import android.graphics.Movie;
import android.graphics.Point;
import android.graphics.drawable.AnimationDrawable;
import android.os.Bundle;
import android.util.Log;
import android.view.MotionEvent;
import android.view.View;
import android.widget.ImageView;
import android.view.View.OnTouchListener;
import android.view.animation.OvershootInterpolator;
public class GifAnimationDemo extends Activity implements OnTouchListener {
/** Called when the activity is first created. */
ImageView image;
static int i=0;
AnimationDrawable rocketAnimation;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
System.out.println(\"\\tmoviestart121321=\"+i);
image=(ImageView)findViewById(R.id.imageView1);
image.setOnTouchListener(this);
}
@Override
public boolean onTouch(View v, MotionEvent event) {
/*image.setBackgroundResource(R.drawable.babyanim);
rocketAnimation = (AnimationDrawable)image.getBackground();
if (event.getAction() == MotionEvent.ACTION_DOWN) {
rocketAnimation.start();
rocketAnimation.isOneShot();
return true;
}
*/
if (event.getAction() == MotionEvent.ACTION_DOWN) {
setContentView(new GIFView(this));
}
else
{setContentView(R.layout.main);
}
return false;
}
class GIFView extends View {
Movie movie;
InputStream is=null;
long moviestart;
private long startTime;
private long endTime;
private long duration=100000;
public GIFView(Context context) {
super(context);
is=context.getResources().openRawResource(R.drawable.baby1);
movie=Movie.decodeStream(is);
}
@Override
protected void onDraw(Canvas canvas) {
canvas.drawColor(0xFFCCCCCC);
super.onDraw(canvas);
//long now=android.os.SystemClock.uptimeMillis();
long curTime = System.currentTimeMillis();
// float percentTime = (float) (curTime - startTime)
// (float) (endTime - startTime);
//System.out.println(\"now=\"+now);
// first time
moviestart = 0;
System.out.println(\"\\tmoviestart=\"+i);
int relTime = (int)((curTime - moviestart) % movie.duration()) ;
// System.out.println(\"time=\"+relTime+\"\\treltime=\"+movie.duration());
// movie.setTime((int) (now+movie.duration()));
// movie.duration();
movie.setTime(relTime);
movie.draw(canvas,20,20);
this.invalidate();
}
@Override
protected void onAnimationEnd() {
// TODO Auto-generated method stub
Log.e(\"Animation end\",\"time\");
super.onAnimationEnd();
}
public void onAnimateMove(float dx, float dy, long duration) {
startTime = System.currentTimeMillis();
endTime = startTime + duration;
}
}
}
没有找到相关结果
已邀请:
0 个回复