今天我就来简单的说说属性动画是怎么使用的
1.先上代码
ValueAnimator animator = ValueAnimator.ofInt(getMaxHeight(),0);//创建出ValueAnimator的对象
animator.addUpdateListener(new AnimatorUpdateListener(){
@Override
public void onAnimationUpdate(ValueAnimator animation) {
int tempHeight = (Integer) animation.getAnimatedValue();//得到中间值
LayoutParams layoutParams2 = ll_footer
.getLayoutParams();
layoutParams2.height = tempHeight;
ll_footer.setLayoutParams(layoutParams2);
}});
animator.setDuration(2000);
animator.start();
private int getMaxHeight() {
//ll_footer.getHeight();//此时有可能获取到的是0,因为有可能ll_footer没有进行测量
//对ll_footer进行测量,768是屏幕宽度,这里对宽做了一些限制,最多是屏幕宽度减去2个边距,对height没有限制;
int size = 768-UiUtils.dip2px(10)*2;
int childWidthMeasureSpec = MeasureSpec.makeMeasureSpec(size, MeasureSpec.AT_MOST);
ll_footer.measure(childWidthMeasureSpec, 0);
return ll_footer.getMeasuredHeight();
}
我们要实现的是点击后布局下拉的效果,使用的是属性动画,利用属性动画产生的中间值改变view的height来实现的
2.第二种实现方式
ObjectAnimator objAnimator = ObjectAnimator.ofFloat(ll_footer, "pivotY", getMaxHeight(),0);
objAnimator.setDuration(2000);
objAnimator.start();
参数说明,ll_footer是动画的作用母表,pivotY消失作用的属性,getMaxHeight()是起始位置,0表示终点;而pivotY这个是根据什么取的呢?so easy! ll_footer.setXXX,看他有没有xxx这个属性就是了,几个,第一个字母要小写;