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/drawable
File
Light01.png
Light02.png
Light03.png
Write
loading.xml
Put 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.xml
In 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.