Android利用android:indeterminateDrawable来实现ProgressBar三种方式

方式1:(效果为补间动画一样)

    <ProgressBar
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:indeterminate="true"
        android:indeterminateDrawable="@anim/loading" />
其中动画loading:

<?xml version="1.0" encoding="UTF-8"?>
<animation-list android:oneshot="false"
  xmlns:android="http://schemas.android.com/apk/res/android">
  <item android:duration="60" android:drawable="@drawable/load_1" />
  <item android:duration="60" android:drawable="@drawable/load_3" />
  <item android:duration="60" android:drawable="@drawable/load_5" />
  <item android:duration="60" android:drawable="@drawable/load_7" />
  <item android:duration="60" android:drawable="@drawable/load_9" />
  <item android:duration="60" android:drawable="@drawable/load_11" />
  <item android:duration="60" android:drawable="@drawable/load_13" />
  <item android:duration="60" android:drawable="@drawable/load_15" />
</animation-list>

方式2:(效果为自定义图片让其不断的旋转)

    <ProgressBar
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:indeterminate="true"
        android:indeterminateDrawable="@drawable/progressbar" />
其中progressbar:

<?xml version="1.0" encoding="utf-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android" >

    <item>
        <rotate
            android:drawable="@drawable/load"
            android:fromDegrees="0.0"
            android:pivotX="50.0%"
            android:pivotY="50.0%"
            android:toDegrees="360.0" />
     <span style="white-space:pre">	</span>    <!-- 其中360.0值越大,转的圈圈越快 -->
    </item>

</layer-list>

方式三:(效果为自定义颜色让其不断的旋转)

    <ProgressBar
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:indeterminate="true"
        android:indeterminateDrawable="@drawable/progressbar2" />
其中progressbar2:

<pre name="code" class="html"><?xml version="1.0" encoding="utf-8"?>
<rotate xmlns:android="http://schemas.android.com/apk/res/android"
    android:fromDegrees="0"
    android:pivotX="50%"
    android:pivotY="50%"
    android:toDegrees="360" >
    <shape
        android:innerRadiusRatio="3"
        android:shape="ring"
        android:thicknessRatio="8"
        android:useLevel="false" >
        <gradient
            android:centerColor="#FFFFFF"
            android:centerY="0.50"
            android:endColor="#1E90FF"
            android:startColor="#000000"
            android:type="sweep"
            android:useLevel="false" />
    </shap


 

 

已标记关键词 清除标记
相关推荐
©️2020 CSDN 皮肤主题: 大白 设计师:CSDN官方博客 返回首页