怎样绘制圆形进度条,如下图所示的图像?

问题描述 投票:1回答:1

进度条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;  

这不是给我的进度条,如下图所示,怎样绘制进度条,如下图: enter image description here

任何帮助将heartly赞赏。三江源,快乐编码。

android xml xamarin.android
1个回答
1
投票

尝试这种解决方案,我想你会得到你想要的输出

<?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
    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" />
© www.soinside.com 2019 - 2024. All rights reserved.