android gif不显示动画,android – 播放动画gif作为电影只显示画布背景

我想在我的

Android应用程序中播放动画gif.

我注意到WebView可以正常使用这段代码:

webview.loadUrl("file:///android_asset/gif.gif");

不幸的是,webView太占用内存,我的应用程序经常崩溃.

我看过很多像这样使用Movie的教程:

public class GIFView extends View {

private Movie movie;

private long moviestart;

public GIFView(Context context) throws IOException {

super(context);

movie = Movie.decodeStream(getResources().getAssets().open("gif.gif"));

}

public GIFView(Context context,AttributeSet attrs) throws IOException {

super(context,attrs);

movie = Movie.decodeStream(getResources().getAssets().open("gif.gif"));

}

public GIFView(Context context,AttributeSet attrs,int defStyle)

throws IOException {

super(context,attrs,defStyle);

movie = Movie.decodeStream(getResources().getAssets().open("gif.gif"));

}

private long _start_time;

@Override

protected void onDraw(Canvas canvas) {

canvas.drawColor(Color.RED);

super.onDraw(canvas);

long _current_time = android.os.SystemClock.uptimeMillis();

if (0 == _start_time) {

_start_time = _current_time;

}

if (null != movie) {

final int _relatif_time = (int) ((_current_time - _start_time) % movie

.duration());

movie.setTime(_relatif_time);

Log.i("",""+_relatif_time);

double scalex = (double) this.getWidth() / (double) movie.width();

double scaley = (double) this.getHeight() / (double) movie.height();

canvas.scale((float) scalex,(float) scaley);

movie.draw(canvas,(float) scalex,(float) scaley)

}

this.invalidate();

}

}

当我得到一个大的红色窗口时,我可以看到Canvas被绘制,并且我添加了Log,我可以看到我的电影不是null并且有一个长度!

不幸的是,除了大红色矩形之外,画布上没有任何内容,我已经使用不同的gif文件进行了测试.

知道为什么这不起作用吗?

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值