Android 4.1 ImagView显示不了gif图片

Android JellyBean 4.1  ImagView显示不了gif图片

https://groups.google.com/forum/?fromgroups=#!topic/android-developers/SuBm1kAuAMw

It occurs only when the bitmap loaded from the GIF has the wrong density and gets auto-scaled by the framework.

Romain Guy
Android framework engineer

即当gif图片需要系统framework缩放时,android 4.1有个bug导致不能正确显示,而在之前的系统上是可以正常显示的。

解决方法:

An easy workaround is to put your GIF in drawable-nodpi/ instead and to perform the scaling use Bitmap.createScaledBitmap() (this API does not cause the bug to happen.) Alternatively you should think about using PNG instead. GIFs scaled at runtime are converted to ARGB_8888 bitmaps so you lose the benefit of low memory usage anyway.

即将所有gif图片放在资源 res/drawable-nodpi 目录下,这样系统不会自动缩放。

如需要缩放,需要调用Bitmap.createScaledBitmap() 来手工缩放。

总体来看,Android平台建议少用或不用gif图片,推荐png格式图片。

猜你喜欢

转载自ericbaner.iteye.com/blog/1671370