如何制作带有指示器图像的自定义进度条,例如 whatsapp?

How to make custom progress bar with indicator image, like whatsapp?

我在你的 res->drawable 文件夹中创建了一个名为 customprogressbar.xml 的 XML 文件:

<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>
        <gradient
                android:startColor="#000001"
                android:centerColor="#0b131e"
                android:centerY="1.0"
                android:endColor="#0d1522"
                android:angle="270"
        />
    </shape>
   </item>

  <!-- Define the progress properties like start color, end color etc -->
  <item android:id="@android:id/progress">
    <clip>
        <shape>
            <gradient
                android:startColor="#007A00"
                android:centerColor="#007A00"
                android:centerY="1.0"
                android:endColor="#06101d"
                android:angle="270"
            />
        </shape>
    </clip>
    </item>
</layer-list>

<ProgressBar
    android:id="@+id/progressBar1"
    style="?android:attr/progressBarStyleHorizontal"
    android:progressDrawable="@drawable/custom_progressbar"         
    android:layout_width="wrap_content"
    android:layout_height="wrap_content" />

现在我有了颜色,但我需要在 fill 和 remainig 之间放置指示图像。

有什么想法吗?

您看到的是 Seekbar 而不是普通的 Progressbar。圆形指示器称为缩略图,您可以添加任何喜欢的图像(以及自定义进度条)。

<SeekBar ...
    android:thumb="@drawable/your_thumb"
    android:progressDrawable="@drawable/progress_bar_layers"
 />

如果"indicator image"表示那里的圆圈,那么我不确定这是否可以用ProgressBar来完成。

在我看来,这更像是一个 SeekBar,然后是一个 ProgressBar。它们几乎相同,除了 SeekBar 具有 "thumb" 属性。这对你有用:

<SeekBar
   android:id="@+id/seekBar"
   android:layout_width="match_parent"
   android:layout_height="wrap_content"
   android:thumb="@drawable/thumb_image"
   android:progressDrawable="@drawable/customprogressbar.xml"
/>