Android uses Animation-list for frame-by-frame Animation and android for frame-by-frame Animation.

Source: Internet
Author: User

Android uses Animation-list for frame-by-frame Animation and android for frame-by-frame Animation.
What we want to achieve

Prepare resource files and place them in res/drawableFile


Light01.png

Light02.png

Light03.png

Write loading.xmlPut in res/drawable
<! -- Animation-list: root tag oneshot: Indicates whether to display only once. If it is set to false, the loop playback animation will be continuously played. android: duration indicates the animation duration of the image --> <? Xml version = "1.0" encoding = "UTF-8"?> <Animation-list xmlns: android = "http://schemas.android.com/apk/res/android" android: oneshot = "false"> <item android: drawable = "@ drawable/light01" android: duration = "50"/> <item android: drawable = "@ drawable/light02" android: duration = "50"/> <item android: drawable = "@ drawable/light03" android: duration = "50"/> </animation-list>
In activity_main.xmlIn the layout file, write
<? Xml version = "1.0" encoding = "UTF-8"?> <LinearLayout xmlns: android = "http://schemas.android.com/apk/res/android" android: layout_width = "fill_parent" android: layout_height = "fill_parent" android: orientation = "vertical"> <ImageView android: id = "@ + id/main_img_loading" android: layout_width = "wrap_content" android: layout_height = "wrap_content" android: padding = "5px" android: src = "@ drawable/loading"/> <Button android: id = "@ + id/main_bt_start" android: layout_width = "wrap_content" android: layout_height = "wrap_content" android: padding = "5px" android: text = ""/> <Button android: id = "@ + id/main_bt_stop" android: layout_width = "wrap_content" android: layout_height = "wrap_content" android: padding = "5px" android: text = "stop"/> </LinearLayout>
Write in Activity like this
Bt_start.setOnClickListener (new OnClickListener () {@ Override public void onClick (View v) {// obtain AnimationDrawable animationDrawable = (AnimationDrawable) animationIV. getDrawable (); // start animation animationDrawable. start () ;}}); bt_stop.setOnClickListener (new OnClickListener () {@ Override public void onClick (View v) {// get AnimationDrawable animationDrawable = (AnimationDrawable) animationIV. getDrawable (); // stop the animation animationDrawable. stop ();}});

If you are interested, follow my Blog. My column will continue to update the Android Studio authoritative tutorial and the NDK configuration and compilation at the 2015 I/O conference, I will share it with you all.
I also received an invitation from CSND's lecturer. Later I will record these Android Studio tutorials as videos.

/*** -------------- * Welcome to reprint | reprinted please note * -------------- * if it is helpful to you, please click | top | * -------------- * Please keep humble | you will go further * -------------- * @ author zsl * @ github https://github.com/yy1300326388 * @ blog http://blog.csdn.net/yy1300326388 */

Copyright Disclaimer: This article is an original article by the blogger and cannot be reproduced without the permission of the blogger.

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.