The way to play GIF animation in Android _android

Source: Internet
Author: User

Because of the project, you have to have an animated wait effect, the first time to think of is GIF (lazy, easy), but tried a lot of it is said to be able to play the GIF control, but also wrote, but put on the Phantom of the mobile phone is not play, all think of a trick, since GIF can be played in the browser, the Android WebView also can play, wrote a demo, sure enough to play.

1, put the GIF file into the Android resource folder

2, write HTML, put the Android GIF source into the webview inside to load

<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, the use of the 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,
" 
 

OK, now it's ready to play and it feels like it can fit any model.

The above is a small set to introduce Android to play GIF animation tricks, hope to help everyone!

Related Article

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.