http://blog.csdn.net/riyuegonghe/article/details/9283479
http://weavora.com/blog/2012/02/07/android-how-to-use-animated-gif/
To date Android platform supports a sufficiently large number of media formats. See documentation here. Among the declared graphic formats you’ll find the one we are interested – GIF. Generally speaking this format does not cause any difficulties until you’ll try to use a GIF file with animation. In this case, the standard class ImageViewdisplays GIF file as a usual static image. Doing search you can find forums stating that Android platform doesn’t fully support GIF, that animated GIF files cannot be used. Nevertheless you can still solve this problem and I’ll show you how.
There are at least two ways:
It is difficult to say which solution is better, however there is one important point. Although WebView is a part of any Android SDK, the ability to play animated GIF files only appeared from version Android 2.2 (API level 8). So if you plan support for vide range of devices, then second option is likely more acceptable for you. I’ll further focus on it.
It is not quite fair to say that class Movie is well documented. Otherwise, this article probably would be useless :-) So, let’s try to create a separate component that can play animated GIF files using class Movie.
OK, creating a new class GIFView, inherited from View:
1234567891011121314151617181920 |
package
com
.
wvr
.
widget
;
import
android.content.Context
;
import
android.util.AttributeSet
;
import
android.view.View
;
public
class
GIFView
extends
View
{
public
GIFView
(
Context
context
)
{
super
(
context
);
}
public
GIFView
(
Context
context
,
AttributeSet
attrs
)
{
super
(
context
,
attrs
);
}
public
GIFView
(
Context
context
,
AttributeSet
attrs
,
int
defStyle
)
{
super
(
context
,
attrs
,
defStyle
);
}
}
|
Now let’s add new variable of type Movie to our class and initialize it
12345678910111213141516171819202122232425262728293031 |