【问题标题】:Android: How to round off end of progress, in a progress-bar?Android:如何在进度条中结束进度?
【发布时间】:2021-03-14 22:34:02
【问题描述】:

如何使进度条结束。下图中是我目前拥有的。如您所见,开始和结束都是圆形的。我还想在进展结束的地方四舍五入。我该怎么做?

我的 custom_progressbar.xml

<?xml version="1.0" encoding="utf-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">

    <!-- Define the background properties like color etc -->
    <item android:id="@android:id/background">
        <shape>
            <corners android:radius="8dp" />
            <solid android:color="@color/progressBarStrokeColor" />
        </shape>
    </item>
    
    <!-- Define the progress properties like start color, end color etc -->
    <item android:id="@android:id/progress">
        <clip>
            <shape>
                <corners android:radius="8dp" />
                <gradient
                    android:angle="180"
                    android:centerColor="@color/purple_700"
                    android:centerY="1.0"
                    android:endColor="#000000"
                    android:startColor="@color/red" />
            </shape>
        </clip>
    </item>
</layer-list>

【问题讨论】:

  • 尝试将半径更改为 45dp
  • 我尝试更改背景的半径,但进度并没有任何变化。现在背景的圆角半径为 45dp。

标签: android xml progress-bar


【解决方案1】:

请试试这个我将&lt;clip/&gt;标签更改为&lt;scale/&gt;并将scaleWidth设置为100%: consult the official documentation

<?xml version="1.0" encoding="utf-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">

    <!-- Define the background properties like color etc -->
    <item android:id="@android:id/background">
        <shape>
            <corners android:radius="8dp" />
            <solid android:color="@android:color/darker_gray" />
        </shape>
    </item>

    <!-- Define the progress properties like start color, end color etc -->
    <item android:id="@android:id/progress">
        <scale android:scaleWidth="100%">
            <shape>

                <corners android:radius="8dp" />
                <gradient

                    android:angle="180"
                    android:centerColor="@color/purple_700"
                    android:centerY="1.0"
                    android:endColor="#000000"
                    android:startColor="@android:color/holo_red_light" />
            </shape>
        </scale>
    </item>
</layer-list>

这是输出:

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2011-01-02
    • 1970-01-01
    • 1970-01-01
    • 2014-08-05
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多