android获取状态栏高度+属性动画注意事项

状态栏就是手机最上方显示电量 wifi标记的东西,有时候得的考虑他的高度。不然有问题

        //获取状态栏高度
        int statusBarHeight1 = -1;
        //获取status_bar_height资源的ID
        int resourceId = getResources().getIdentifier("status_bar_height", "dimen", "android");
        if (resourceId > 0) {
            //根据资源ID获取响应的尺寸值
            statusBarHeight1 = getResources().getDimensionPixelSize(resourceId);
        }


属性动画实例:

private ObjectAnimator animator;
private ObjectAnimator animator1;
private AnimatorSet set;
animator = ObjectAnimator.ofFloat(image002, "x", x, 0);
animator.setDuration(1000);
animator1 = ObjectAnimator.ofFloat(image002, "y", y-statusBarHeight1, h - h001-statusBarHeight1);
animator1.setDuration(1000);
set = new AnimatorSet();
set.playTogether(animator, animator1);
set.start();

注意事项:此处ofFloat里面的坐标是当前view也就是image002相对于父布局的坐标。不是相对屏幕的坐标。父布局为activity的话,需要考虑状态栏以及actionbar的高度。

下面是设置速率变化的,可据此实现抛物线自由落体等效果

AccelerateDecelerateInterpolator        在动画开始与介绍的地方速率改变比较慢,在中间的时侯加速
AccelerateInterpolator        在动画开始的地方速率改变比较慢,然后开始加速
CycleInterpolator        动画循环播放特定的次数,速率改变沿着正弦曲线
DecelerateInterpolator        在动画开始的地方速率改变比较慢,然后开始减速
LinearInterpolator        在动画的以均匀的速率改变

下面是属性:

 alpha 透明度 
 rotation z轴旋转
 rotationX x轴旋转 
 rotationY y轴旋转 
 translationX x水平偏移
 translationY y水平偏移
 ScaleX x轴缩放 
 ScaleY y轴缩放

background 背景

总结:属性动画,只要是对象有getter和setter的属性都能用,对任何属性都有用,本质就是调用对象的setter和getter方法,且不限制对象是否是view都行。

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值