先写一下AnimatorSet的动画类型:
可以xml定义
AnimatorSet set = (AnimatorSet) AnimatorInflater.loadAnimator(myContext, R.anim.property_animator);set.setTarget(myObject);set.start();
1)AccelerateDecelerateInterpolator:先加速再减速。
2)AccelerateInterpolator:一直加速。
3)AnticipateInterpolator:先往后一下,再嗖的一声一往无前。
4)AnticipateOvershootInterpolator:先往后一下,再一直往前超过终点,再往回收一下。
5)BounceInterpolator:最后像个小球弹几下。
6)CycleInterpolator:重复几次,感觉就是环形进度条那种,具体我还没试过。
7)DecelerateInterpolator:一直减速。
8)LinearInterpolator:线性,这个就是我们上面讲到的很均匀的了。
9)OvershootInterpolator:到了终点之后,超过一点,再往回走。有个参数可以定义,超过的力度。
ObjectAnimator fadeOut = ObjectAnimator.ofFloat(v1, "alpha", 0f);
ObjectAnimator mover = ObjectAnimator.ofFloat(v2, "translationX", -500f, 0f);
ObjectAnimator fadeIn = ObjectAnimator.ofFloat(v2, "alpha", 0f, 1f);
AnimatorSet animSet = new AnimatorSet().play(mover).with(fadeIn).after(fadeOut);;
animSet.start();
animationSet = new AnimatorSet();
animationSet.playTogether(
ObjectAnimator.ofFloat(layout_bottom, "alpha", 1,0,1),
ObjectAnimator.ofFloat(layout_bottom, "translationX", 0f,400f,0f),
ObjectAnimator.ofFloat(layout_bottom, "rotation", 0,180,360)
);
animationSet.setDuration(1000);
animationSet.setTarget(layout_bottom);
animationSet.addListener(new AnimatorListener() {
@Override
public void onAnimationStart(Animator arg0) {
Log.e(TAG,"onAnimationStart");
}
@Override
public void onAnimationRepeat(Animator arg0) {
Log.e(TAG,"onAnimationRepeat");
}
@Override
public void onAnimationEnd(Animator arg0) {
Log.e(TAG,"onAnimationEnd");
}
@Override
public void onAnimationCancel(Animator arg0) {
Log.e(TAG,"onAnimationCancel");
}
});
animationSet.start();
当然,我会记录一些其他部分:
改变RelativeLayout的高度
举个例子
RelativeLayout layout_relative_header = (RelativeLayout)this.findViewById(R.id.layout_relative_header);
private void changeHeaderLayout(){
int width= layout_relative_header.getLayoutParams().width;
int height = layout_relative_header.getLayoutParams().height;
height = ScreenUtils.getIntPixels(this, 56); //small
// height = ScreenUtils.getIntPixels(this, 220); //big
RelativeLayout.LayoutParams param = new RelativeLayout.LayoutParams(width,height);
param.addRule(RelativeLayout.CENTER_VERTICAL, 1);
layout_relative_header.setLayoutParams(param);
}
// 下面是我的ScreenUtils方法:
public static int getIntPixels(final Context context, final int dp) {
return getIntPixels(context.getResources(), dp);
}
public static int getIntPixels(final Resources resources, final int dp) {
float pixels = TypedValue.applyDimension(COMPLEX_UNIT_DIP, dp,
resources.getDisplayMetrics());
return (int) Math.floor(pixels + 0.5F);
}
animatorSet = new AnimatorSet();
animatorSet.playTogether(ObjectAnimator.ofFloat(
layout_bottom, "alpha", 1, 0), ObjectAnimator
.ofFloat(layout_bottom, "translationY", 0f, 800f));
animatorSet.setDuration(600);
animatorSet.setInterpolator(new AnticipateInterpolator());
objectAnimator = ObjectAnimator.ofFloat(iv_controller,
"rotation", 90f, 0f);
objectAnimator.setDuration(600);
objectAnimator
.setInterpolator(new AnticipateInterpolator());
animatorSet.start();
objectAnimator.start();
layout_bottom.postDelayed(new Runnable() {
@Override
public void run() {
layout_bottom.setVisibility(View.VISIBLE);
}
}, 100);
//AnimatorSet类与AnimationSet别搞混,而且必须在3.0以上版本中才有哦... //此类可以根据一个特殊的顺序来播放Animator对象中的动画,而Animator则是一个 //可以支持set结点设置动画的详细信息,如:开始、结束等...,set相信大家不是很陌生了吧 //以下形式即:set结点动画 /**<setandroid:ordering=["together" ¦ "sequentially"]> <objectAnimator android:propertyName="string" android:duration="int" android:valueFrom="float ¦ int ¦ color" android:valueTo="float ¦ int ¦ color" android:startOffset="int" android:repeatCount="int" android:repeatMode=["repeat" ¦ "reverse"] android:valueType=["intType" ¦ "floatType"]/> <animator android:duration="int" android:valueFrom="float ¦ int ¦ color" android:valueTo="float ¦ int ¦ color" android:startOffset="int" android:repeatCount="int" android:repeatMode=["repeat" ¦ "reverse"] android:valueType=["intType" ¦ "floatType"]/> <set> ... </set> </set>*/
http://blog.csdn.net/ritterliu/article/details/7513822
http://tech.ddvip.com/2013-03/1362574852191505.html