Android shape properties create a circular progress bar

1. Achieve results

2. Implementation code: [1] shape_ Drawable.xml file

<?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】 We set the custom ring to a rotation animation, use the rotation animation to customize the style of a ring progress circle, and finally assign the custom style to the progress component. progress_ Rotate file

<?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】 Custom progress style: customprogressstyle file

<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】 Apply to progress component

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

summary

The above is the Android shape attribute created by Xiaobian. I hope it will help you. If you have any questions, please leave me a message, and Xiaobian will reply to you in time. Thank you very much for your support to our website! If you think this article is helpful to you, welcome to reprint, please indicate the source, thank you!

The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
THE END
分享
二维码
< <上一篇
下一篇>>