android显示gif图片
2015-10-28 11:41
423 查看
1、public class MainActivity extends Activity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
}
}
2、<activity
android:name=".MainActivity"
android:label="@string/app_name"
android:screenOrientation="portrait"
android:hardwareAccelerated="false"/>
3、 <com.i.gifview.GifView
android:id="@+id/gv"
android:layout_width="100dp"
android:layout_height="100dp"
android:layout_margin="20dp" />
4、public class GifView extends View {
private long movieStart;
private Movie movie;
// 此处必须重写该构造方法
public GifView(Context context, AttributeSet attributeSet) {
super(context, attributeSet);
movie = Movie.decodeStream(getResources().openRawResource(R.drawable.car));
}
@Override
protected void onDraw(Canvas canvas) {
long curTime = android.os.SystemClock.uptimeMillis();
// 第一次播放
if (movieStart == 0) {
movieStart = curTime;
}
if (movie != null) {
int duraction = movie.duration();
int relTime = (int) ((curTime - movieStart) % duraction);
movie.setTime(relTime);
movie.draw(canvas, 0, 0);
invalidate();
}
super.onDraw(canvas);
}
}
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
}
}
2、<activity
android:name=".MainActivity"
android:label="@string/app_name"
android:screenOrientation="portrait"
android:hardwareAccelerated="false"/>
3、 <com.i.gifview.GifView
android:id="@+id/gv"
android:layout_width="100dp"
android:layout_height="100dp"
android:layout_margin="20dp" />
4、public class GifView extends View {
private long movieStart;
private Movie movie;
// 此处必须重写该构造方法
public GifView(Context context, AttributeSet attributeSet) {
super(context, attributeSet);
movie = Movie.decodeStream(getResources().openRawResource(R.drawable.car));
}
@Override
protected void onDraw(Canvas canvas) {
long curTime = android.os.SystemClock.uptimeMillis();
// 第一次播放
if (movieStart == 0) {
movieStart = curTime;
}
if (movie != null) {
int duraction = movie.duration();
int relTime = (int) ((curTime - movieStart) % duraction);
movie.setTime(relTime);
movie.draw(canvas, 0, 0);
invalidate();
}
super.onDraw(canvas);
}
}
相关文章推荐
- Android 支付宝接口调用
- 彻底解决Android 应用方法数不能超过65K的问题
- Android.mk相关知识
- android 处理器crash刊物
- Android中的各种访问权限Permission含义
- android中在广播中弹出pop框的局限性
- 为Android应用程序读取/dev下设备而提权
- android:Adapter中设置textview字体颜色
- 关于android布局的两个属性dither和tileMode
- 解决android:background背景图片被拉伸问题
- Android机型适配之痛[干货分享]
- Android中的PopupWindow详解
- Android-自定义PopupWindow
- Android 数据库打包随APK发布
- Android中PopupWindow的用法(位置、动画、焦点)
- Android PopupWindow 的使用
- Android基础入门教程——8.3.9 Paint API之—— ColorFilter(颜色过滤器)(1-3)
- 【Android】页面迁移时先弹出键盘问题解决
- Android中如何获取系统应用程序列表与AndroidManifest.xml信息
- 正在运行的android程序,按home键之后退回到桌面,在次点击程序图标避免再次重新启动程序解决办法