animated-rotate 的 drawable 的卡顿与解决办法

想定义一个旋转的drawable,系统源码中看到这个东西 style="?android:attr/progressBarStyle" 发现他用了一个类似如下的 drawable ,

<animated-rotate xmlns:android="http://schemas.android.com/apk/res/android"
    android:drawable="@drawable/progressbar_circle"
    android:pivotX="50%"
    android:pivotY="50%"
    android:framesCount="12"
    android:frameDuration="100" />

这其中用到了两个系统私有属性 framesCount 和 frameDuration,体验感就是动画很流畅,但如果你想自定义,就只能用下面这种,体验感就是一卡一卡的。WTF

<?xml version="1.0" encoding="utf-8"?>
<animated-rotate xmlns:android="http://schemas.android.com/apk/res/android"
    android:drawable="@drawable/progressbar_circle"
    android:pivotX="50%"
    android:pivotY="50%"
    android:fromDegrees="0.0"
    android:interpolator="@android:anim/linear_interpolator"
    android:repeatCount="-1"
    android:toDegrees="359.0"
    android:duration="100" />

那有没有啥解决办法呢?同样系统提供的layer-list 就好多了。如下

<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
<item>
    <rotate
        android:drawable="@drawable/progressbar_circle"
        android:pivotX="50%"
        android:pivotY="50%"
        android:repeatCount="-1"
        android:fromDegrees="0"
        android:duration="100"
        android:toDegrees="359"/>
</item>
</layer-list>

但很快你就会发现,这里面的android:duration 是不起作用的,WTF,
咋办,如果是要给progressBar用 可以再定义一个style 指定其一个android:indeterminateDuration属性 如下 ,这样 ,终于能正常了,唉,google

<!-- progressbar 自定义旋转风格-->
    <style name="progressbarCircle" parent="Widget.AppCompat.ProgressBar">
        <item name="android:indeterminateDrawable">@drawable/progress_medium_bak</item>
        <item name="android:indeterminateDuration">500</item>
    </style>
  • 5
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值