/**
* 动态改变view的高度动画效果,动画时长300毫秒[android属性动画默认时长]
* 原理:动画改变view LayoutParams.height的值
* @param view 要进行高度改变动画的view
* @param startHeight 动画前的view的高度
* @param endHeight 动画后的view的高度
*/
public static void changeViewHeightAnimatorStart(final View view, final int startHeight, final int endHeight){
if(view!=null&&startHeight>=0&&endHeight>=0){
ValueAnimator animator=ValueAnimator.ofInt(startHeight,endHeight);
animator.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() {
@Override
public void onAnimationUpdate(ValueAnimator animation) {
ViewGroup.LayoutParams params=view.getLayoutParams();
params.height= (int) animation.getAnimatedValue();
view.setLayoutParams(params);
}
});
animator.start();
}
}
网友评论