Android Shape属性创建环形进度条

时间:2022-07-27
本文章向大家介绍Android Shape属性创建环形进度条,主要内容包括其使用实例、应用技巧、基本知识点总结和需要注意事项,具有一定的参考价值,需要的朋友可以参考一下。

1,实现效果

2,实现代码: 【1】 shape_drawable.xml文件

<?xml version="1.0" encoding="utf-8"? 
<shape xmlns:android="http://schemas.android.com/apk/res/android"
  android:innerRadius="20dp"
  android:shape="ring"
  android:thickness="8dp"
  android:useLevel="false"  

  <gradient android:angle="0"
    android:startColor="@color/normal"
    android:centerColor="#5027844F"
    android:endColor="#fff"
    android:useLevel="false"
    android:type="sweep"
    / 
</shape 

【2】 我们将该自定义环形圈设置给一个旋转动画,并利用该旋转动画自定义成一个环形进度圈的style,最后将该自定义的style赋值给Progress组件。 progress_rotate文件

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

【3】 自定义Progress的style: CustomProgressStyle文件

<style name="CustomProgressStyle"  
  <item name="android:indeterminateDrawable" @drawable/progress_rotate</item 
  <item name="android:minWidth" 72dp</item 
  <item name="android:maxWidth" 72dp</item 
  <item name="android:minHeight" 72dp</item 
  <item name="android:maxHeight" 72dp</item 
</style  

【4】 应用到Progress组件

<ProgressBar
   android:layout_width="100dp"
   android:layout_height="100dp"
   android:layout_centerInParent="true"
   style="@style/CustomProgressStyle"
   android:indeterminateDuration="700"
   / 

总结

以上所述是小编给大家介绍的Android Shape属性创建环形进度条,希望对大家有所帮助,如果大家有任何疑问请给我留言,小编会及时回复大家的。在此也非常感谢大家对ZaLou.Cn网站的支持! 如果你觉得本文对你有帮助,欢迎转载,烦请注明出处,谢谢!