日韩av黄I国产麻豆传媒I国产91av视频在线观看I日韩一区二区三区在线看I美女国产在线I麻豆视频国产在线观看I成人黄色短片

歡迎訪問(wèn) 生活随笔!

生活随笔

當(dāng)前位置: 首頁(yè) >

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

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

問(wè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.

來(lái)源: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的全部?jī)?nèi)容,希望文章能夠幫你解決所遇到的問(wèn)題。

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