The effect we want to achieve
Prepare the resource file to dropres/drawableIn the file
Light01.png
Light02.png
Light03.png
Writeloading.xmlPut inres/drawable
<!--animation-list: Root tag oneshot: Indicates whether to show only once, set to false will not stop the animation of the animated Android:d Uration represents the animation of the picture time--- <?xml version= "1.0" encoding= "Utf-8"?><animation-list xmlns:android="Http://schemas.android.com/apk/res/android" android:oneshot="false" > <itemandroid:drawable="@drawable/light01"android:duration="50" /> <itemandroid:drawable= "@drawable/light02"android:duration=" "/> <itemandroid:drawable="@drawable/light03"android:duration= "/>" </animation-list>
Inactivity_main.xmlLayout file, so 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_wid th = "wrap_content" android:layout_height= "wrap_content" android:padding = "5px" android:src = "@drawab Le/loading "/> <button android:id = "@+id/main_bt_start" android:layout_width< /span>= "wrap_content" android:layout_height = "wrap_content" android:padding = "5px" android:text = "start" /> <button android:id="@+id/main_bt_stop"android:layout_width="Wrap _content "android:layout_height=" Wrap_content "android:padding=" 5px " Android:text="Stop" /> </linearlayout>
In the activity, write like this.
Bt_start.setonclicklistener (NewOnclicklistener () {@Override Public void OnClick(View v) {//Get animationdrawableAnimationdrawable = (animationdrawable) animationiv.getdrawable ();//Start animationAnimationdrawable.start (); } }); Bt_stop.setonclicklistener (NewOnclicklistener () {@Override Public void OnClick(View v) {//Get animationdrawableAnimationdrawable = (animationdrawable) animationiv.getdrawable ();//Stop animationAnimationdrawable.stop (); } });
Interested children's shoes can follow my blog, my column will continue to update the Android Studio authoritative tutorial, as well as I/O assembly on the NDK configuration and compilation, I will also share to everyone.
And I received an invitation from CSND's instructor, and later I'll record the use of these Android studio videos.
/** * -------------- * 欢迎转载 | 转载请注明 * -------------- * 如果对你有帮助,请点击|顶| * -------------- * 请保持谦逊 | 你会走的更远 * -------------- * @author zsl * @github https://github.com/yy1300326388 * @blog http://blog.csdn.net/yy1300326388 */
Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.
Android uses animation-list to animate frames by frame