android 解码 gif 时间,Android 解码播放GIF图像

这篇博客介绍了如何在Android中使用TypegifView自定义一个带有延迟切换和停止/启动功能的GIF轮播图组件。它展示了如何解析GIF资源、设置图片显示顺序和定时更新图片,适合于了解Android UI定制和动画开发的读者。
摘要由CSDN通过智能技术生成

package com.terry.gif;

import android.content.Context;

import android.content.res.TypedArray;

import android.graphics.Bitmap;

import android.graphics.Canvas;

import android.graphics.Paint;

import android.util.AttributeSet;

import android.view.View;publicclassTypegifView extends View implements Runnable {

gifOpenHelper gHelper;privateboolean isStop=true;intdelta;

String title;

Bitmap bmp;//construct - refer for javapublicTypegifView(Context context) {this(context,null);

}//construct - refer for xmlpublicTypegifView(Context context, AttributeSet attrs) {

super(context, attrs);//添加属性TypedArray ta=context.obtainStyledAttributes(attrs,

R.styleable.gifView);intn=ta.getIndexCount();for(inti=0; i

setSrc(id);break;caseR.styleable.gifView_delay:intidelta=ta.getInteger(R.styleable.gifView_delay,1);

setDelta(idelta);break;caseR.styleable.gifView_stop:

boolean sp=ta.getBoolean(R.styleable.gifView_stop,false);if(!sp) {

setStop();

}break;

}

}

ta.recycle();

}/**

* 设置停止

*

* @param stop*/publicvoidsetStop() {

isStop=false;

}/**

* 设置启动*/publicvoidsetStart() {

isStop=true;

Thread updateTimer=newThread(this);

updateTimer.start();

}/**

* 通过下票设置第几张图片显示

* @param id*/publicvoidsetSrc(intid) {

gHelper=newgifOpenHelper();

gHelper.read(TypegifView.this.getResources().openRawResource(id));

bmp=gHelper.getImage();//得到第一张图片}publicvoidsetDelta(intis) {

delta=is;

}//to meaure its Width & Height@OverrideprotectedvoidonMeasure(intwidthMeasureSpec,intheightMeasureSpec) {

setMeasuredDimension(measureWidth(widthMeasureSpec),

measureHeight(heightMeasureSpec));

}privateintmeasureWidth(intmeasureSpec) {returngHelper.getWidth();

}privateintmeasureHeight(intmeasureSpec) {returngHelper.getHeigh();

}protectedvoidonDraw(Canvas canvas) {//TODO Auto-generated method stubcanvas.drawBitmap(bmp,0,0,newPaint());

bmp=gHelper.nextBitmap();

}publicvoidrun() {//TODO Auto-generated method stubwhile(isStop) {try{this.postInvalidate();

Thread.sleep(gHelper.nextDelay()/delta);

}catch(Exception ex) {

}

}

}

}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值