本文共 2685 字,大约阅读时间需要 8 分钟。
属性动画 // Added in API level 11 public abstract class Animator extends Object implements Cloneable{} //Known Direct Subclasses AnimatorSet ValueAnimator //Known Indirect Subclasses ObjectAnimator TimeAnimator //Animator的方法 addListener(Animator.AnimatorListener listener); isPaused(); isRunning(); isStarted(); Animator clone(); start(); end(); cancel(); resume(); setDuration(long duration); setStartDelay(long startDelay); setTarget(Object target); ObjectAnimator: ObjectAnimator.ofFloat(Object target, String propertyName, float... values); ObjectAnimator.ofInt(Object target, String propertyName, int... values); ObjectAnimator.ofObject(T target, Property<T, V> property, TypeEvaluator<V> evaluator, V... values); setFloatValues(float... values); setIntValues(int... values); setPropertyName(String propertyName); setTarget(Object target); //ObjectAnimator() 逐个添加参数 ValueAnimator: //a simple timing engine for running animations which calculate animated values and set them on target objects AnimatorSet: playSequentially(List<Animator> items); play(Animator anim); playTogether(Animator... items); playSequentially(Animator... items); ObjectAnimator oa = ObjectAnimator.ofFloat(iv, "translationY", 10, 50,20,150); ObjectAnimator oa = ObjectAnimator.ofFloat(iv, "scaleY", 1, 2, 1, 2,3,5,1); ObjectAnimator oa = ObjectAnimator.ofFloat(iv, "alpha", 0, 0.5f, 0, 1,0,1,0,0); ObjectAnimator oa = ObjectAnimator.ofFloat(iv, "rotationX", 0, 180, 90, 360); AnimatorSet as = new AnimatorSet(); ObjectAnimator oa = ObjectAnimator.ofFloat(iv, "translationX", 10, 50, 20, 100); ObjectAnimator oa2 = ObjectAnimator.ofFloat(iv, "scaleY", 0.1f, 2, 1, 2); ObjectAnimator oa3 = ObjectAnimator.ofFloat(iv, "alpha", 0, 0.5f, 0, 1); ObjectAnimator oa4 = ObjectAnimator.ofFloat(iv, "rotationY", 0, 180, 90, 360); as.setDuration(2000); as.setTarget(iv); as.playSequentially(oa, oa2, oa3, oa4); //往集合中添加动画 //挨个飞 as.playTogether(oa, oa2, oa3, oa4); //一起飞 as.start(); xml /res/animator/^^.xml AnimatorInflater: static Animator loadAnimator(Context context, int id) ; <set xmlns:android="http://schemas.android.com/apk/res/android" > <objectAnimator android:propertyName="translationX" //backgroundColor android:duration="2000" android:valueFrom="10" android:valueTo="100" android:startOffset="int" android:repeatCount="int" android:repeatMode="reverse" android:valueType=""/> <animator android:duration="" android:valueFrom="" android:valueTo="" android:repeatCount="" android:repeatMode="" android:interpolator="" android:valueType="" /> </set> //代码示例 ObjectAnimator colorAnim = (ObjectAnimator)AnimatorInflater.loadAnimator(MainActivity.this,R.animator.color_anim); color.setTarget(this); colorAnim.start();转载地址:http://ibegi.baihongyu.com/