自定义水平进度条背景

Customize the background of horizontal progress bar

我有一个水平进度条,我想更改背景。我想把背景分成 4 个部分,如下所示(只是我的进度条的形状是矩形的)。我发现有很多例子展示了改变进度条背景颜色的方法,但是我不知道如何划分背景。有什么想法吗?

您可以使用图层 ID 在进度条背景 XML 中分别指定背景、主要进度和次要进度。以下是默认 Holo 进度条的设置方式:

<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
    <item android:id="@android:id/background"
          android:drawable="@drawable/progress_bg_holo_light" />

    <item android:id="@android:id/secondaryProgress">
        <scale android:scaleWidth="100%"
               android:drawable="@drawable/progress_secondary_holo_light" />
    </item>

    <item android:id="@android:id/progress">
        <scale android:scaleWidth="100%"
               android:drawable="@drawable/progress_primary_holo_light" />
    </item>
</layer-list>

您可能想使用 <clip> 而不是 <scale>,但您明白了。