在当前progressBar位置添加项目 - 创建自定义进度条

时间:2017-06-09 09:18:08

标签: android progress-bar customization

我正在尝试创建一个如下所示的自定义进度条:

enter image description here

我设法创建布局,但我不知道如何将该圆圈放在当前的progressBar进度位置。有人知道如何实现这个目标吗?

我的xml布局如下所示:

<!-- Define the background properties like color etc -->
<item android:id="@android:id/background">
    <shape>
        <solid android:color="#ffffff" />
        <corners android:radius="1dip" />
    </shape>
</item>

<!-- Define the progress properties like start color, end color etc -->
<item android:id="@android:id/progress">
    <clip>
        <shape>
            <solid android:color="#42cbf4"
                android:width="40dp"/>
        </shape>
    </clip>
</item>

我还为透明背景添加了一个linearLayout 我尝试在进度项中添加另一个椭圆形状,或者为secondProgress创建另一个形状,但没有任何效果。 现在,它看起来像这样:

enter image description here

2 个答案:

答案 0 :(得分:1)

此类ProgressBar被称为&#34;搜索栏&#34; ,并且在线有很多实现。也许你可以通过输入&#34; seek&#34;在The Android Arsenal上搜索它。正在搜索。顺便说一下,我在网站上找到了一个简单而漂亮的网站;你可以找到它here

答案 1 :(得分:0)

我找到了我要找的东西。而不是 ProgressBar 我使用了 SeekBar ,它实现了我需要的 thumb 。对于自定义,我使用了相同的布局,而对于拇指,我使用了这个片段:

thumb.xml:

<?xml version="1.0" encoding="UTF-8"?>

<gradient
    android:angle="270"
    android:endColor="#026b91"
    android:startColor="#026b91" />

<size
    android:height="30dp"
    android:width="30dp" />

custom_progress_bar.xml:

<!-- Define the background properties like color etc -->
<item android:id="@android:id/background">
    <shape>
        <solid android:color="#ffffff" />
        <corners android:radius="1dip" />
    </shape>
</item>

<!-- Define the progress properties like start color, end color etc -->
<item android:id="@android:id/progress">
    <clip>
        <shape>
            <solid android:color="#42cbf4"
                android:width="40dp"/>
        </shape>
    </clip>
</item>

为了将这些自定义添加到我的progressBar,我使用了以下代码:

<SeekBar
   android:id="@+id/seekBar"
   android:thumb="@drawable/thumb"
   android:progressDrawable="@drawable/custom_progress_bar"
   android:layout_width="match_parent"
   android:layout_height="wrap_content" />

有关详细信息,我使用了此主题 Custom seekbar (thumb size, color and background)