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

更多相关文章

  1. NPM 和webpack 的基础使用
  2. 【阿里云镜像】使用阿里巴巴DNS镜像源——DNS配置教程
  3. 替换或者删除Android(安卓)4.0的app
  4. 文件对应
  5. android studio 54 下载进度条
  6. Android(安卓)的网络编程(8)-文件上传功能
  7. Android(安卓)图片的缓存机制分析
  8. Android(安卓)IjkPlayer 视频播放器
  9. Android实时抓取日志,生成文件

随机推荐

  1. android开发笔记之也谈android开发入门
  2. android绘制过程
  3. Android(安卓)-- 跨应用启动Service
  4. Android(安卓)发送Post请求上传图片(以Inp
  5. android获取手机电话信息
  6. Android(安卓)动画之RotateAnimation应用
  7. Android本地化开发技巧
  8. Android(安卓)JNI技术, NDK开发
  9. Android中常用的bitmap处理方法 (bitmap工
  10. Android(安卓)电量优化篇