Android 属性动画valueAnimator和objectAnimator的使用

今天我就来简单的说说属性动画是怎么使用的

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这个属性就是了,几个,第一个字母要小写;

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值