在布局中加入gif动图
来源:互联网 发布:数据恢复免费破解版 编辑:程序博客网 时间:2024/06/09 23:07
创建一个类MyGifView,java代码如下:
package com.example.gif;import android.content.Context;import android.graphics.Canvas;import android.graphics.Movie;import android.util.AttributeSet;import android.view.View;public class MyGifView extends View {private long movieStart;private Movie movie;// 重写该构造方法public MyGifView(Context context, AttributeSet attributeSet) {super(context, attributeSet);// 以文件流(InputStream)读取进gif图片资源movie = Movie.decodeStream(getResources().openRawResource(R.drawable.loading));}@Overrideprotected 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);}}
xml文件:
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent" android:layout_height="match_parent" android:paddingBottom="@dimen/activity_vertical_margin" android:paddingLeft="@dimen/activity_horizontal_margin" android:paddingRight="@dimen/activity_horizontal_margin" android:paddingTop="@dimen/activity_vertical_margin" tools:context="com.example.gif.MainActivity" > <com.example.gif.MyGifView android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_margin="20dp" /></RelativeLayout>
0 0
- 在布局中加入gif动图
- 在Qt中加入GIF动图
- 如何在Ubuntu 16.04中创建GIF动图
- GIF动图 SegmentControl
- 制作Gif动图
- 加载gif动图
- 设置gif动图
- android-pulltorefresh 下拉加载中使用gif动图
- 从网络中获取图片或动图(gif)
- android 播放gif动图
- GDI+播放GIF动图
- Android显示Gif动图
- Fresco加载gif动图
- android gif动图播放
- ps构建gif动图
- Fresco加载GIF动图
- python 显示 gif 动图
- c# 使用gif动图
- Linux学习笔记--1.简介
- socket setSoTimeOut
- Qt 实现的拷贝文件夹的函数
- UIView 设置圆角和边框备忘
- LightOJ 1037 - Agent 47(状压DP)
- 在布局中加入gif动图
- jquery给table动态添加tr
- C#中的委托与事件
- java 正则 抠出内容并用值进行替换
- 类方法isAssignableFrom、instanceof和asSubclass的区别及实例
- 实习整理(十三)
- NSUserDefaults简介和简单使用
- java.lang.NoSuchFieldError: deferredExpression
- 论垃圾邮件危害性及U-Mail邮件系统必杀技