循环ProgressBar背景:Android Xamarin

Erm*_*bel 10 android xamarin.android android-progressbar progress-bar xamarin

我有一个循环的进度条,它工作正常.但是背景没有出现,即使我已经在xml可绘制文件中给出了"背景"的形状,并且从圆圈的右侧开始进度(如图所示) ).我希望它从顶部开始.

在此输入图像描述

这是我的代码:

 <ProgressBar
        android:id="@+id/progressBarToday"
        style="?android:attr/progressBarStyleHorizontal"
        android:layout_width="50dip"
        android:layout_height="50dip"
        android:layout_centerInParent="true"
        android:indeterminate="false"
        android:max="60"
        android:progress="0"
        android:progressDrawable="@drawable/progressbar" />
Run Code Online (Sandbox Code Playgroud)

progressbar.xml

    <?xml version="1.0" encoding="UTF-8" ?>
    <layer-list xmlns:android="http://schemas.android.com/apk/res/android">
    <item android:id="@android:id/background"> <---not working!
    <shape
        android:innerRadiusRatio="3"
        android:shape="ring"
        android:thicknessRatio="7.0">
        <solid android:color="@color/red"/>
        </shape>
    </item>
    <item android:id="@android:id/progress">
    <shape
        android:innerRadiusRatio="3"
        android:shape="ring"
        android:thicknessRatio="7.0">
        <solid android:color="@color/blue"/>
        </shape>
    </item>
    </layer-list>
Run Code Online (Sandbox Code Playgroud)

我使用以下代码来设置进度:

    ProgressBar pb = (ProgressBar)FindViewById (Resource.Id.progressBarToday);  
    _progressBar.Progress = _progressCount;
Run Code Online (Sandbox Code Playgroud)

为什么没有出现背景?我怎样才能从顶部开始进步?

有人请帮忙,谢谢.

小智 27

您需要将以下属性添加到背景项:

android:useLevel="false"
Run Code Online (Sandbox Code Playgroud)

像这样:

<?xml version="1.0" encoding="UTF-8" ?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
  <item android:id="@android:id/background"> <---not working!
    <shape
        android:innerRadiusRatio="3"
        android:shape="ring"
        android:useLevel="false"
        android:thicknessRatio="7.0">
        <solid android:color="@color/red"/>
    </shape>
  </item>
  <item android:id="@android:id/progress">
    <shape
        android:innerRadiusRatio="3"
        android:shape="ring"
        android:thicknessRatio="7.0">
        <solid android:color="@color/blue"/>
    </shape>
  </item>
</layer-list>
Run Code Online (Sandbox Code Playgroud)


小智 5

要从顶部开始,您可以使用"旋转

<item android:id="@android:id/progress">
    <rotate
        android:fromDegrees="-90"
        android:toDegrees="-90">
        <shape
            android:innerRadiusRatio="3"
            android:shape="ring"
            android:thicknessRatio="7.0"
            android:useLevel="true">
            <solid android:color="@color/blue"/>
        </shape>
     </rotate>
</item>
Run Code Online (Sandbox Code Playgroud)


Erm*_*bel 4

我成功了

     <ProgressBar
            android:id="@+id/progressBarToday"
            style="?android:attr/progressBarStyleHorizontal"
            android:layout_width="50dip"
            android:layout_height="50dip"
            android:layout_centerInParent="true"
            android:indeterminate="false"
            android:max="60"
            android:progress="0"
            android:background="@drawable/bg" // here is working background
            android:progressDrawable="@drawable/progressbar" />
Run Code Online (Sandbox Code Playgroud)

  • @Erma Isabel 你可以输入@drawable/bg 和@drawable/progressbar 代码吗?提前致谢 (4认同)