日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當(dāng)前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

android play gif,Play.gif image in android without using webview

發(fā)布時間:2023/12/1 编程问答 36 豆豆
生活随笔 收集整理的這篇文章主要介紹了 android play gif,Play.gif image in android without using webview 小編覺得挺不錯的,現(xiàn)在分享給大家,幫大家做個參考.

問題

I tried like this, which i found on the net to play gif images:

private class MYGIFView extends View {

Movie movie;

InputStream is = null;

long moviestart;

public MYGIFView(Context context) {

super(context);

// Provide your own gif animation file

is = context.getResources().openRawResource(R.drawable.mygif);

movie = Movie.decodeStream(is);

}

@Override

protected void onDraw(Canvas canvas) {

canvas.drawColor(Color.WHITE);

super.onDraw(canvas);

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

System.out.println("now=" + now);

if (moviestart == 0) { // first time

moviestart = now;

}

System.out.println("\tmoviestart=" + moviestart);

int relTime = (int) ((now - moviestart) % movie.duration());

System.out.println("time=" + relTime + "\treltime="

+ movie.duration());

movie.setTime(relTime);

movie.draw(canvas, this.getWidth() / 2 - 20,

this.getHeight() / 2 - 40);

this.invalidate();

}

Though many have said that they got their desired result.

I have put the gif image in drawable.

I am getting movie.duration() null.

Please suggest where am i wrong or if is there any way.

回答1:

Android cannot play GIF files without WebView. You must break it apart into frames and animate it yourself.

I found on another StackOverflow post this bit of software from XoyoSoft, called GifSplitter, that can split a GIF into frames. You would then want to use AnimationDrawable to combine those.

It would look something like this:

// Your files:

res\drawable-xxxx\frame1.jpg

res\drawable-xxxx\frame2.jpg

res\drawable-xxxx\frame3.jpg

// ...

res\drawable-xxxx\frame99.jpg

Then, there is an example in the AnimationDrawable documentation above that will show how to display those images.

Lastly, you must load and play the animation; that, too, is detailed in the AnimationDrawable documentation.

來源:https://stackoverflow.com/questions/11806320/play-gif-image-in-android-without-using-webview

總結(jié)

以上是生活随笔為你收集整理的android play gif,Play.gif image in android without using webview的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網(wǎng)站內(nèi)容還不錯,歡迎將生活随笔推薦給好友。