简体   繁体   English

状态之间有间隙的水平进度条

[英]Horizontal Progress bar with a gap in between the states

I am looking for a way to create the desired progress bar with a gap between the complete and incomplete state like this我正在寻找一种方法来创建所需的进度条,在完整和不完整的 state 之间有一个差距,就像这样想要的形象 . . The gap should not be visible when progress is 0 or full.当进度为 0 或已满时,间隙不应可见。 It should only be displayed when there is some progress but still incomplete.它应该只在有一些进展但仍未完成时显示。 The Gap should be transparent.间隙应该是透明的。

You can design custom drawable for that that and use secondary progress with progress+1 value.您可以为此设计自定义可绘制对象,并使用具有progress+1值的辅助进度。 Sharing code snippet for reference.共享代码片段以供参考。

<ProgressBar
        android:id="@+id/progress_limit"
        style="?android:attr/progressBarStyleHorizontal"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:indeterminate="false"
        android:max="100"
        android:maxHeight="10dip"
        android:minHeight="10dip"
        android:progress="50"
        android:padding="10dp"
        android:secondaryProgress="52"
        android:progressDrawable="@drawable/progress_limit" />

progress_limit.xml progress_limit.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">
        <shape>
            <corners
                android:radius="5dip" />

            <solid android:color="#bbbbbb"/>
        </shape>
    </item>
    <item
        android:id="@android:id/secondaryProgress">
        <clip>
            <shape>
                <corners
                    android:radius="5dip" />
                <solid android:color="#ffffff"/>
            </shape>
        </clip>
    </item>
    <item
        android:id="@android:id/progress">
        <clip>
            <shape>
                <corners
                    android:radius="5dip" />
                <solid android:color="#ff0000"/>
            </shape>
        </clip>
    </item>
</layer-list>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM