Android: how to play Gif videos; android: how to play gif videos
As a result of the project, there must be an animation wait effect. The first thought of it was Gif (lazy, easy to worry about). However, I tried a lot of controls that are said to be capable of playing Gif videos and wrote them, however, if you put it on meizu's mobile phone, you won't be able to play the video. Now that Gif can be played in a browser, android WebView can also play the video, and a Demo can be written to play the video.
1. Place the gif file in the android resource folder.
2. Write an html file and place the android gif source in WebView to load the file.
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent" android:layout_height="match_parent" android:paddingLeft="@dimen/activity_horizontal_margin" android:paddingRight="@dimen/activity_horizontal_margin" android:paddingTop="@dimen/activity_vertical_margin" android:paddingBottom="@dimen/activity_vertical_margin" tools:context=".MainActivity"> <WebView android:id="@+id/webview" android:layout_width="match_parent" android:layout_height="match_parent"> </WebView></RelativeLayout>
3. Use in code
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); WebView webView = (WebView) findViewById(R.id.webview); webView.loadDataWithBaseURL(null, "<HTML><body bgcolor='#f3f3f3'><div align=center></div></body>
Now you can play the video. I feel like I can adapt to any model.