Android中实现ProgressBar菊花旋转的动画效果

在一些常见到的加载中需要显示一个加载动画,如旋转的菊花,旋转的圈圈等等动画…,然后我们现在就来说下怎么去试下它吧

一.菊花的旋转动画

在这里插入图片描述

1.新建一个drawable文件

在res/drawable下新建一个progressbar_style.xml文件定义一个旋转动画

<animated-rotate xmlns:android="http://schemas.android.com/apk/res/android"
    android:drawable="@drawable/loading_01"  //菊花图片路径
    android:fromDegrees="0"
    android:pivotX="50%"
    android:pivotY="50%"
    android:toDegrees="360">
</animated-rotate>
2.在布局ProgressBar控件中引入使用
 <ProgressBar
        android:background="@color/transparent"
        android:indeterminateDuration="2"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:indeterminateBehavior="repeat" 
        android:indeterminateDrawable="@drawable/progressbar_style"/>
二. 圆圈旋转动画

在这里插入图片描述

步骤跟上面是一样的,使用也是一样的,只是在progressbar_style.xml中定义的动画效果是不一样的

<animated-rotate xmlns:android="http://schemas.android.com/apk/res/android"
    android:fromDegrees="0"
    android:pivotX="50%"
    android:pivotY="50%"
    android:toDegrees="360">
    <shape
        android:innerRadius="8dp"
        android:thickness="3dp"
        android:shape="ring"
        android:useLevel="false">
        <gradient
            android:centerY="0.50"
            android:endColor="#cccccc"
            android:startColor="@color/white"
            android:type="sweep"
            android:useLevel="false" />
    </shape>

<!--  android:pivotX     动画执行的起点x坐标 50%代表相对自身宽度的
android:innerRadius  内环的半径
android:thickness  环的厚度
android:useLevel  只有当我们的shape使用在LevelListDrawable中时,这个值为true,否则为false
android:centerY 渐变中心Y的相对位置,值为0-1
android:type  渐变类型,还有linear,radial两种类型,线性渐变和放射渐变-->

</animated-rotate>
  • 1
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值