Android: how to play Gif videos; android: how to play gif videos

Source: Internet
Author: User

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.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.