属性动画(Property Animation)资源
2013-11-22 09:25
405 查看
Animator 代表一个属性动画,但它只是一个抽象类,通常会使用它的子类:AnimatorSet、ValueAnimator、ObjectAnimator、TimeAnimator。
定义属性动画的 XML 资源文件能以如下三个元素中的任意一个作为根元素。
<set.../>:它是一个父元素,用于包含其他<objectAnimator.../>、<animator.../>或 <set.../>子元素,该元素定义的资源代表 AnimatorSet 对象。
<objectAnimator.../>:用于定义 ObjectAnimator 动画。
<animator.../>:用于定义 ValueAnimator 动画。
实例:不断渐变的背景色
main.xml
color_anim.xml
AnimatorTest.java
定义属性动画的 XML 资源文件能以如下三个元素中的任意一个作为根元素。
<set.../>:它是一个父元素,用于包含其他<objectAnimator.../>、<animator.../>或 <set.../>子元素,该元素定义的资源代表 AnimatorSet 对象。
<objectAnimator.../>:用于定义 ObjectAnimator 动画。
<animator.../>:用于定义 ValueAnimator 动画。
实例:不断渐变的背景色
main.xml
<?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:orientation="vertical" android:layout_width="match_parent" android:layout_height="match_parent" android:id="@+id/container" > </LinearLayout>
color_anim.xml
<?xml version="1.0" encoding="utf-8"?> <objectAnimator xmlns:android="http://schemas.android.com/apk/res/android" android:propertyName="backgroundColor" android:duration="3000" android:valueFrom="#FF8080" android:valueTo="#8080FF" android:repeatCount="infinite" android:repeatMode="reverse" android:valueType="intType"> </objectAnimator>
AnimatorTest.java
package org.crazyit.res; import android.animation.AnimatorInflater; import android.animation.ArgbEvaluator; import android.animation.ObjectAnimator; import android.app.Activity; import android.content.Context; import android.os.Bundle; import android.view.View; import android.widget.LinearLayout; /** * Description: * <br/>site: <a href="http://www.crazyit.org">crazyit.org</a> * <br/>Copyright (C), 2001-2014, Yeeku.H.Lee * <br/>This program is protected by copyright laws. * <br/>Program Name: * <br/>Date: * @author Yeeku.H.Lee kongyeeku@163.com * @version 1.0 */ public class AnimatorTest extends Activity { @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main); LinearLayout container = (LinearLayout) findViewById(R.id.container); // 添加MyAnimationView组件 container.addView(new MyAnimationView(this)); } public class MyAnimationView extends View { public MyAnimationView(Context context) { super(context); // 加载动画资源 ObjectAnimator colorAnim = (ObjectAnimator) AnimatorInflater .loadAnimator(AnimatorTest.this, R.animator.color_anim); colorAnim.setEvaluator(new ArgbEvaluator()); // 对该View本身应用属性动画 colorAnim.setTarget(this); // 开始指定动画 colorAnim.start(); } } }
相关文章推荐
- 解决centos 6.3 yum安装软件时找不到镜像问题
- 解决centos 6.3 yum安装软件时找不到镜像问题
- PetShop的系统架构设计
- linux find 2
- openstack之role篇
- 服务器优化——Sysctl、Apache、MySQL
- xshell总是在最前端解决办法
- shell中echo变换颜色的用法
- centos 杀死进程命令
- centos彻底删除文件夹、文件命令(centos 新建、删除、移动、复制等命令)
- 系统架构领域的一些学习材料 by林仕鼎
- Linux下svn操作文档
- linux运行apache出现403错误
- ECSHOP优化 设置404页面
- Linux和Unix系统的关系和区别详细介绍
- 架构师的第一步:学习两种抽象视角(Abstraction View)
- dll部署到Tomcat方法
- OpenCV学习(38) 人脸识别(3)
- Nginx配置优化详解
- shell脚本分析 nginx日志访问次数最多及最耗时的页面