android 显示gif图片
16lz
2021-12-04
package com.lxy;import android.app.Activity;import android.content.Context;import android.graphics.Canvas;import android.graphics.Movie;import android.os.Bundle;import android.view.View;public class MyActivity extends Activity { /** Called when the activity is first created. */private MyCustomView mView; private Movie mMovie; private long mMovieStart; public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); mView = new MyCustomView(this); setContentView(mView); } //自定义一个类,继承View class MyCustomView extends View{ public MyCustomView(Context context) { super(context); //以文件流的方式读取文件 mMovie = Movie.decodeStream( getResources().openRawResource(R.drawable.bear)); } @Override protected void onDraw(Canvas canvas) { long curTime = android.os.SystemClock.uptimeMillis(); //第一次播放 if(mMovieStart == 0){ mMovieStart = curTime; } if(mMovie != null){ int duration = mMovie.duration(); int relTime = (int)((curTime - mMovieStart)% duration); mMovie.setTime(relTime); mMovie.draw(canvas, 0, 0); //强制重绘 invalidate(); } super.onDraw(canvas); } } }
转载自: http://blog.csdn.net/y13872888163/article/details/6446235
更多相关文章
- NPM 和webpack 的基础使用
- 【阿里云镜像】使用阿里巴巴DNS镜像源——DNS配置教程
- 替换或者删除Android(安卓)4.0的app
- 文件对应
- android studio 54 下载进度条
- Android(安卓)的网络编程(8)-文件上传功能
- Android(安卓)图片的缓存机制分析
- Android(安卓)IjkPlayer 视频播放器
- Android实时抓取日志,生成文件