Android:GIF、invalidate
2013-06-20 20:05
239 查看
仿照apiDemos的例子,com.example.android.apis.graphics.BitmapDecode,直接修改来用:
public class PlayGifActivity extends Activity { @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(new SampleView(this,R.drawable.animated_gif)); } private static class SampleView extends View { private Movie mMovie; private long mMovieStart; // Set to false to use decodeByteArray private static final boolean DECODE_STREAM = true; private static byte[] streamToBytes(InputStream is) { ByteArrayOutputStream os = new ByteArrayOutputStream(1024); byte[] buffer = new byte[1024]; int len; try { while ((len = is.read(buffer)) >= 0) { os.write(buffer, 0, len); } } catch (java.io.IOException e) { } return os.toByteArray(); } public SampleView(Context context,int resID) { super(context); setFocusable(true); java.io.InputStream is; is = context.getResources().openRawResource(resID); if (DECODE_STREAM) { mMovie = Movie.decodeStream(is); } else { byte[] array = streamToBytes(is); mMovie = Movie.decodeByteArray(array, 0, array.length); } } @Override protected void onDraw(Canvas canvas) { canvas.drawColor(0xFFCCCCCC); long now = android.os.SystemClock.uptimeMillis(); if (mMovieStart == 0) { // first time mMovieStart = now; } if (mMovie != null) { int dur = mMovie.duration(); if (dur == 0) { dur = 1000; } int relTime = (int) ((now - mMovieStart) % dur); mMovie.setTime(relTime); mMovie.draw(canvas, getWidth() - mMovie.width(), getHeight() - mMovie.height()); invalidate();//重绘方法,调用下一帧 } } } }
相关文章推荐
- Android view中的requestLayout和invalidate方法
- Android面试,View绘制流程以及invalidate()等相关方法分析
- Android笔记:invalidate()和postInvalidate() 的区别及使用
- android中Invalidate和postInvalidate的区别
- Android开源项目:GifView——Android显示GIF动画
- 如何在android上 使用gif图片
- Android手机录制屏幕并转gif图
- Android开源控件----Android显示GIF图像控件------android-gif-drawable
- android中Invalidate和postInvalidate的区别
- android中使用gif
- android gif
- Android移植NDK子项目--以android-gif-drawable为例
- Android中View绘制流程以及invalidate()等相关方法分析
- Android录屏命令、Android录Gif、Android录视频
- Android中GIF动图的播放控制和监听详解
- Android加载网络GIF完整解决方案
- android中invalidate()的使用小结
- Android中View绘制流程以及invalidate()等相关方法分析
- android gif view
- android平台TextView使用ImageSpan画廊GIF图像