进度条xml如下:

<ProgressBar
            android:id="@+id/progressBarCircular"
            style="?android:attr/progressBarStyleHorizontal"
            android:layout_width="200dp"
            android:layout_height="200dp"
            android:layout_alignTop="@id/squareView_3"
            android:layout_toRightOf="@id/squareView_3"
            android:layout_marginTop="-105dp"
            android:layout_marginLeft="40dp"
            android:indeterminate="false"
            android:max="100"
            android:progress="0"
            android:background="@color/BlackText"
            android:progressDrawable="@drawable/circular_progressbar" />


Circular_progressbar.xml如下:

<?xml version="1.0" encoding="UTF-8" ?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
  <item android:id="@+id/background">
    <shape
            android:innerRadiusRatio="3"
            android:shape="ring"
            android:thicknessRatio="8.0">
        <solid android:color="@color/DarkGrey" />
    </shape>
  </item>
  <item android:id="@+id/progress">
    <shape
            android:innerRadiusRatio="2.5"
            android:shape="ring"
            android:thicknessRatio="12.0">
        <solid android:color="@color/green" />
    </shape>
  </item>
</layer-list>


并设置进度:

ProgressBar pb = (ProgressBar)view.FindViewById(Resource.Id.progressBarCircular);
pb.Progress = 75;


这没有给我进度条,如下图所示,如何绘制进度条,如下图所示:
android - 如何绘制圆形进度条,如下图所示?-LMLPHP

任何帮助将不胜感激。谢谢,快乐编码。

最佳答案

试试这个解决方案,我想您会得到想要的输出

<?xml version="1.0" encoding="UTF-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
    <item android:id="@android:id/background">
        <shape
            android:angle="0"
            android:shape="ring"
            android:thickness="10dp"
            android:useLevel="false">
            <solid android:color="#eeeeee" />
        </shape>
    </item>
    <item android:id="@android:id/progress">
        <rotate
            android:fromDegrees="270"
            android:toDegrees="270">
            <shape
                android:angle="0"
                android:shape="ring"
                android:thickness="10dp"
                android:useLevel="true">
                <solid android:color="#81ca33" />
            </shape>
        </rotate>
    </item>
</layer-list>


对于旋转,我将ProgressBar视图中的属性调整为:-

<ProgressBar
    android:id="@+id/progressBarView"
    android:layout_width="200dp"
    android:layout_height="200dp"
    style="?android:attr/progressBarStyleHorizontal"
    android:indeterminateOnly="false"
    android:rotation="-90"
    android:max="100"
    android:progressDrawable="@drawable/circular_progressbar" />

09-13 07:45