Android Drawable Animation 学习
来源:互联网 发布:服装数据分析怎么分析 编辑:程序博客网 时间:2024/05/18 17:45
Drawable Animation(Frame Animation) Drawable Animation(Frame Animation):帧动画,就像GIF图片,通过一系列Drawable依次显示来模拟动画的效果。在XML中的定义方式如下:
<?xml version="1.0" encoding="utf-8"?><animation-list android:oneshot="false" xmlns:android="http://schemas.android.com/apk/res/android"> <item android:duration="400" android:drawable="@drawable/send_loading1" /> <item android:duration="400" android:drawable="@drawable/send_loading2" /> <item android:duration="400" android:drawable="@drawable/send_loading3" /> <item android:duration="400" android:drawable="@drawable/send_loading4" /> <item android:duration="400" android:drawable="@drawable/send_loading5" /> <item android:duration="400" android:drawable="@drawable/send_loading1" /></animation-list>
下面通过一个例子演示其作用
目录结构
common_loading_animation.xml
<?xml version="1.0" encoding="utf-8"?><animation-list android:oneshot="false" xmlns:android="http://schemas.android.com/apk/res/android"> <item android:duration="400" android:drawable="@drawable/send_loading1" /> <item android:duration="400" android:drawable="@drawable/send_loading2" /> <item android:duration="400" android:drawable="@drawable/send_loading3" /> <item android:duration="400" android:drawable="@drawable/send_loading4" /> <item android:duration="400" android:drawable="@drawable/send_loading5" /> <item android:duration="400" android:drawable="@drawable/send_loading1" /></animation-list>
horizontal_loading_animation.xml
<?xml version="1.0" encoding="utf-8"?><animation-list android:oneshot="false" xmlns:android="http://schemas.android.com/apk/res/android"> <item android:duration="400" android:drawable="@drawable/progressbar_indeterminate_holo1" /> <item android:duration="400" android:drawable="@drawable/progressbar_indeterminate_holo2" /> <item android:duration="400" android:drawable="@drawable/progressbar_indeterminate_holo3" /> <item android:duration="400" android:drawable="@drawable/progressbar_indeterminate_holo4" /> <item android:duration="400" android:drawable="@drawable/progressbar_indeterminate_holo4" /> <item android:duration="400" android:drawable="@drawable/progressbar_indeterminate_holo5" /> <item android:duration="400" android:drawable="@drawable/progressbar_indeterminate_holo6" /> <item android:duration="400" android:drawable="@drawable/progressbar_indeterminate_holo7" /> <item android:duration="400" android:drawable="@drawable/progressbar_indeterminate_holo8" /> <item android:duration="400" android:drawable="@drawable/progressbar_indeterminate_holo9" /> <item android:duration="400" android:drawable="@drawable/progressbar_indeterminate_holo10" /> <item android:duration="400" android:drawable="@drawable/progressbar_indeterminate_holo11" /> <item android:duration="400" android:drawable="@drawable/progressbar_indeterminate_holo12" /> <item android:duration="400" android:drawable="@drawable/progressbar_indeterminate_holo13" /> <item android:duration="400" android:drawable="@drawable/progressbar_indeterminate_holo14" /> <item android:duration="400" android:drawable="@drawable/progressbar_indeterminate_holo15" /> <item android:duration="400" android:drawable="@drawable/progressbar_indeterminate_holo16" /> <item android:duration="400" android:drawable="@drawable/progressbar_indeterminate_holo17" /> <item android:duration="400" android:drawable="@drawable/progressbar_indeterminate_holo18" /> <item android:duration="400" android:drawable="@drawable/progressbar_indeterminate_holo19" /> <item android:duration="400" android:drawable="@drawable/progressbar_indeterminate_holo20" /> <item android:duration="400" android:drawable="@drawable/progressbar_indeterminate_holo21" /></animation-list>
activity_main.xml
<LinearLayout 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:orientation="vertical" tools:context=".MainActivity" > <RelativeLayout android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_marginTop="20dp" > <ProgressBar android:layout_width="match_parent" android:layout_height="2dp" android:indeterminateDrawable="@drawable/horizontal_loading_animation" /> </RelativeLayout> <LinearLayout android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_marginTop="20dp" android:orientation="vertical" > <ImageView android:id="@+id/iv" android:layout_width="wrap_content" android:layout_height="wrap_content" android:contentDescription="@string/app_name" /> <Button android:id="@+id/bt_start" android:layout_marginTop="10dp" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="开始" /> </LinearLayout></LinearLayout>
MainActivity.java
package com.example.loadingview;import android.app.Activity;import android.graphics.drawable.AnimationDrawable;import android.os.Bundle;import android.view.View;import android.view.View.OnClickListener;import android.widget.Button;import android.widget.ImageView;public class MainActivity extends Activity {@Overrideprotected void onCreate(Bundle savedInstanceState) {super.onCreate(savedInstanceState);setContentView(R.layout.activity_main);findView();}private void findView() {ImageView rocketImage = (ImageView) findViewById(R.id.iv);rocketImage.setBackgroundResource(R.drawable.common_loading_animation);final AnimationDrawable rocketAnimation = (AnimationDrawable) rocketImage.getBackground();Button bt_start = (Button) findViewById(R.id.bt_start);bt_start.setOnClickListener(new OnClickListener() {@Overridepublic void onClick(View v) {rocketAnimation.start();//rocketAnimation.stop();//停止}});}}
详细可参考:http://developer.android.com/guide/topics/graphics/drawable-animation.html
- Android Drawable Animation 学习
- Android-animation-drawable Animation
- Android animation学习笔记之view/drawable animation
- Android之Drawable Animation
- android-Drawable Animation
- Android动画-Drawable Animation
- Drawable Animation(Android动画)
- 【Android基础知识】Drawable Animation和View Animation
- Android Animation——drawable animation
- Android绘图动画---Drawable Animation
- Android动画之Drawable Animation
- Android动画之一:Drawable Animation
- Android动画之一:Drawable Animation
- Android动画之一:Drawable Animation
- Android帧动画Drawable Animation
- Android 动画(2) Drawable Animation
- Android API Guides---Drawable Animation
- Android动画之一:Drawable Animation
- raw socket编写自定义Ip数据包
- Android串口通信实例分析【附源码】
- 黑马程序员--面向对象基础知识(01)
- 坐得越久 死得越快
- nyoj-921-分数矩阵
- Android Drawable Animation 学习
- 数组小运用
- java的零碎知识2
- 数据恢复 FinalData 3.0 & testdisk
- 基于网络视频聊天语音通话的开源框架
- 十四周-数组变化后输出
- Hello World
- 关于sql server批量插入和更新的两种解决方案
- 十四周项目1-1数组运用