开发者

Displaying animated GIFs in Android

开发者 https://www.devze.com 2023-03-25 06:46 出处:网络
I am getting my GIF image as a byte array from the server. Now since android cannot display animated GIFs in the ImageView, I have to decode it and show it as a movie.

I am getting my GIF image as a byte array from the server. Now since android cannot display animated GIFs in the ImageView, I have to decode it and show it as a movie.

The problem that I am facing here is that the GIF that I am getting from the server has its dimensions set for an开发者_如何学C iPhone. So the GIF comes out really small on Android devices with larger screen/resolution.

To fix this I have two alternatives: 1) I could either extract each Bitmap from the GIF and scale them according to my screen size. But for that I will have to mess up the aspect ratio and the image will come out stretched.

2) Or I could ask the server guys to add support for Android devices, so that they could send me the GIF according to my screen size.

Please recommend as to what the best solution would be. Do tell if you have any suggestions of your own.


I would recommend you to go with the second option, one thing that you have to always consider in developing mobile application is Battery Usage, processing image in android rather than having it ready to use from the server, will suffer the device battery and the user absolutely wouldn't be happy with it.


But it is easy to display the gifs in the webview, also you can adjust the settings of the web view objects to display the gif to match the webview.

WebView web = (WebView) findViewById(R.id.webView1);

//this line to load gif from web

web.loadUrl("gif URL");

//this line is to load images from sdcard or assets folder where you can store the images you got from the web service

web.loadUrl("file:///android_asset/yourgif.gif");

//this line is to set the image size fit to the size of the webview

web.getSettings().setDefaultZoom(ZoomDensity.FAR);

Hope you got what I am trying to say...!

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号