一、屬性動畫的基本使用
1.比較常用的幾個動畫類
ValueAnimator、ObjectAnimator、AnimatorSet
ObjectAnimator繼承自Valueanimator
maAnitorSet是動畫集合,可以定義一組動畫
2.具體用法
(1)讓一個對象(view)沿著Y軸向上平移一段距離
Objectanimator.ofFloat(View,quot;translationYquot;,-view.getHight()).star();
( 2 ) 改變一個對象的背景屬性
ValueAnimator colorAnim = ObjectAnimator.ofInt(this,quot;backgroungColorquot;,0xFFFF8080,0FF8080FF);
colorAnim.setDuration(3000);//動畫的時長
(3)動畫集合
AnimatorSet set = new AnimatorSet();
set.playTogether{
ObjectAnimator.ofFloat(view,quot;rotationXquot;,0,360); //旋轉
ObjectAnimator.ofFloat(view,quot;rotationquot;,0,90);
ObjectAnimator.ofFloat(view,quot;translationXquot;,0,90); 平移
ObjectAnimator.ofFloat(view,quot;scaleXquot;,0,1.5f); //縮放
ObjectAnimator.ofFloat(view,quot;alphaquot;,1,0.25f,1);
}
( 4 ) xml文件中使用屬性動畫(放在res/animator/property_animator.xml)
lt;set xmlns:android=quot;http://schemas.android.com/apk/res/androidquot;
android:ordering=quot;togetherquot;gt;
lt;objectAnimator
android:propertyName=quot;xquot;作用對象的屬性名稱
android:duration=quot;300quot;動畫的時長
android:valueFrom=quot;100quot;屬性的開始值
android:valueTo=quot;200quot;屬性的結束值
android:startOffset=quot;100quot;動畫的延遲時間
android:repeatCount=quot;3quot;動畫重復次數
android:repeatMode=quot;restartquot;動畫重復模式
android:valueType=quot;intTypequot;propertyName的屬性類型(intType floatTYpe)
/gt;
使用 :
AnimatorSet set =(AnimatorSet)AnimatorInflater.loadAnimator(Context,R.anim.property_animator.xml);
set.setTarget(view);
set.star();
Tags: 安卓開發
文章來源:http://www.jianshu.com/p/0ad5452e63d8