我想在当前活动中播放一个GIF文件。
我有一个XML文件,其中有一个布局。
我想在同一个类的Activity中播放GIF。
有没有简单的方法在Activity类中播放GIF文件?
我想在当前活动中播放一个GIF文件。
我有一个XML文件,其中有一个布局。
我想在同一个类的Activity中播放GIF。
有没有简单的方法在Activity类中播放GIF文件?
//My activity
public class Gift_Loading extends Activity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
Gif_loading_View view = new Gif_loading_View(this);
setContentView(view);
}
}
//the webView
public class Gif_loading_View extends WebView{
public Gif_loading_View(Context context) {
super(context);
loadUrl("file:///android_asset/loading_position.html");
}
}
<html>
<body bgcolor="white">
<table width="100%" height="100%">
<tr>
<td align="center" valign="center">
<br/>
<br/>
<br/>
<font size="6">Please wait...</font>
<br/>
<br/>
<img src="cyclist_loading.gif" />
</td>
</tr>
</table>
</body>
Android不支持播放动态GIF文件。如果需要播放它们,则需要将其拆分为帧,并逐帧进行动画处理。
这将允许您拆分GIF文件。 http://www.xoyosoft.com/gs/
<pl.droidsonroids.gif.GifTextView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@drawable/first"
/>
这里有一个示例链接, 其中创建了一个自定义的AnimatedGifView
类。
它使用了android.graphics.Movie
类,并重写了onDraw
方法来定期重新绘制视图。以下是摘录:
gifInputStream = context.getResources().openRawResource(R.drawable.myGIFImage);
gifMovie = Movie.decodeStream(gifInputStream);
gifMovie.setTime((int)movieRunDuration);
gifMovie.draw(canvas, 0, 0);
然而,更合适的做法可能是将动画GIF转换为AnimationDrawables
。