如何制作自定义进度条并带有指示器图像,就像WhatsApp一样?

4
我在您的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" />

现在我已经有了颜色,但是我需要放置指示器图像,在填充和剩余之间。

enter image description here

任何想法?

你具体考虑将指示器图像用于什么?是哪种指示器? - Nick Cardoso
如果您查看屏幕截图,您可以看到在“填充”和“剩余”之间有一个点。 - Cabezas
2个回答

7
您看到的是一个SeekBar,而不是一个普通的ProgressBar。圆形指示器称为Thumb,您可以添加任何喜欢的图像(以及自定义进度条)。
<SeekBar ...
    android:thumb="@drawable/your_thumb"
    android:progressDrawable="@drawable/progress_bar_layers"
 />

2
非常感谢。太完美了。我必须制作一个自定义的SeekBar https://dev59.com/hmQo5IYBdhLWcg3wUN3Y - Cabezas

1
如果“指示器图像”是指那个圆形圆圈,那么我不确定这是否可以使用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"
/>

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接