Home >Web Front-end >HTML Tutorial >Android uses Animation-list to implement frame-by-frame animation_html/css_WEB-ITnose

Android uses Animation-list to implement frame-by-frame animation_html/css_WEB-ITnose

WBOY
WBOYOriginal
2016-06-24 11:42:061218browse

The effect we want to achieve

Prepare the resource file and put it under the res/drawable file


light01.png

light02.png

light03.png

Write loading.xml and put it in res/drawable

<!-- animation-list :根标签 oneshot :代表着是否只展示一遍,设置为false会不停的循环播放动画 android :duration 表示该图片的动画时长 -->  <?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 the activity_main.xml layout file, like this 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="停止" /></LinearLayout>

Write like this in Activity

bt_start.setOnClickListener(new OnClickListener()      {      @Override      public void onClick(View v) {      //获取 AnimationDrawable        animationDrawable = (AnimationDrawable) animationIV.getDrawable();          //开始动画        animationDrawable.start();      }  });   bt_stop.setOnClickListener(new OnClickListener()  {      @Override      public void onClick(View v) {     //获取 AnimationDrawable         animationDrawable = (AnimationDrawable) animationIV.getDrawable();         //停止动画         animationDrawable.stop();      }  });  

Interested children can follow my blog. My column will continue to be updated with Android Studio authoritative tutorials and 2015 I/ I will also share with you the configuration and compilation of NDK at the O conference.
And I received an invitation as a lecturer from CSND. I will record these Android Studio usage tutorials into videos later.

/** * -------------- * 欢迎转载 | 转载请注明 * -------------- * 如果对你有帮助,请点击|顶| * -------------- * 请保持谦逊 | 你会走的更远 * -------------- * @author zsl * @github https://github.com/yy1300326388 * @blog http://blog.csdn.net/yy1300326388 */

Copyright statement: This article is an original article by the blogger and may not be reproduced without the blogger's permission.

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn