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

原文:http://blog.csdn.net/chenlove1/article/details/41758977

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

[html]  view plain  copy
  1. <ProgressBar  
  2.     android:layout_width="wrap_content"  
  3.     android:layout_height="wrap_content"  
  4.     android:indeterminate="true"  
  5.     android:indeterminateDrawable="@anim/loading" />  
其中动画loading:

[html]  view plain  copy
  1. <?xml version="1.0" encoding="UTF-8"?>  
  2. <animation-list android:oneshot="false"  
  3.   xmlns:android="http://schemas.android.com/apk/res/android">  
  4.   <item android:duration="60" android:drawable="@drawable/load_1" />  
  5.   <item android:duration="60" android:drawable="@drawable/load_3" />  
  6.   <item android:duration="60" android:drawable="@drawable/load_5" />  
  7.   <item android:duration="60" android:drawable="@drawable/load_7" />  
  8.   <item android:duration="60" android:drawable="@drawable/load_9" />  
  9.   <item android:duration="60" android:drawable="@drawable/load_11" />  
  10.   <item android:duration="60" android:drawable="@drawable/load_13" />  
  11.   <item android:duration="60" android:drawable="@drawable/load_15" />  
  12. </animation-list>  

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

[html]  view plain  copy
  1. <ProgressBar  
  2.     android:layout_width="wrap_content"  
  3.     android:layout_height="wrap_content"  
  4.     android:indeterminate="true"  
  5.     android:indeterminateDrawable="@drawable/progressbar" />  
其中progressbar:

[html]  view plain  copy
  1. <?xml version="1.0" encoding="utf-8"?>  
  2. <layer-list xmlns:android="http://schemas.android.com/apk/res/android" >  
  3.   
  4.     <item>  
  5.         <rotate  
  6.             android:drawable="@drawable/load"  
  7.             android:fromDegrees="0.0"  
  8.             android:pivotX="50.0%"  
  9.             android:pivotY="50.0%"  
  10.             android:toDegrees="360.0" />  
  11.      <span style="white-space:pre">   </span>    <!-- 其中360.0值越大,转的圈圈越快 -->  
  12.     </item>  
  13.   
  14. </layer-list>  

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

[html]  view plain  copy
  1. <ProgressBar  
  2.     android:layout_width="wrap_content"  
  3.     android:layout_height="wrap_content"  
  4.     android:indeterminate="true"  
  5.     android:indeterminateDrawable="@drawable/progressbar2" />  

其中progressbar2(在drawable文件夹下定义如下):

<?xml version="1.0" encoding="utf-8"?>
<rotate
    android:fromDegrees="0"
    android:toDegrees="-1440"
    android:pivotX="50%"
    android:pivotY="50%"
    xmlns:android="http://schemas.android.com/apk/res/android">

    <!--innerRadiusRatio 内圆半径比 -->
    <!--thicknessRatio 厚度比 -->
<shape xmlns:android="http://schemas.android.com/apk/res/android"
    android:shape="ring"
    android:innerRadiusRatio="2.5"
    android:thicknessRatio="10"
    android:useLevel="false">

    <!-- 颜色渐变 sweep表示扫描-->
    <gradient android:type="sweep" android:startColor="#f00"
              android:centerColor="#88ff6666"
              android:endColor="#00000000"></gradient>
</shape>
</rotate>


  • 2
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值