Android ProgressBar进度条

软件发布|下载排行|最新软件

当前位置:首页IT学院IT技术

Android ProgressBar进度条

kaolagirl   2022-05-22 我要评论

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

一.菊花的旋转动画

在这里插入图片描述

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>

Copyright 2022 版权所有 软件发布 访问手机版

声明:所有软件和文章来自软件开发商或者作者 如有异议 请与本站联系 联系我们