使用图片移动Android上的进度条

9
我有这段代码。
这是一个进度条,用红色填充。
<?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>
            <gradient
            android:startColor="#c3c3c3"
                android:centerColor="#c3c3c3"
                android:centerY="0.75"
                android:endColor="#7f7f7f"
                android:angle="270"/>
            <padding android:left="1dp"
            android:top="1dp"
            android:right="1dp"
            android:bottom="1dp"/> 
        <corners android:radius="10dp"/> 
    </shape>
</item>

<item android:id="@android:id/secondaryProgress">
    <clip>
        <shape>
            <gradient
                android:startColor="#234"
                android:centerColor="#234"
                android:centerY="0.75"
                android:endColor="#a24"
                android:angle="270"/>
            <padding android:left="1dp"
                android:top="1dp"
                android:right="1dp"
                android:bottom="1dp"/> 
            <corners android:radius="10dp"/> 
            </shape>
    </clip>
</item>

<item android:id="@android:id/progress">
    <clip>
       <shape>
            <gradient
                android:startColor="#a42c48"
                android:centerColor="#a42c48"
                android:centerY="0.75"
                android:endColor="#eb3e67"
                android:angle="270"/>
            <padding android:left="1dp"
                android:top="1dp"
                android:right="1dp"
                android:bottom="1dp"/> 
            <corners android:radius="10dp"/> 
        </shape>
    </clip>
    </item>
</layer-list>

并且看起来像这样

在此输入图片描述

现在我想添加一张图片,在进度条填充时同时移动,就像下面的图片一样

在此输入图片描述

请帮助我

提前感谢

2个回答

12

也许您可以使用图层列表样式化一个seekbar(而不是progressbar),并将您的图片作为thumb scrubber添加进去?

<SeekBar
    android:id="@+id/seekBar1"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:thumb="@drawable/your_android_image"
    android:progressDrawable="@drawable/your_layerlist_drawable"/>

谢谢Damian的回答。请问你有如何实现的例子吗? - japuentem
1
没问题。我进行了快速测试,看起来很好。您可能希望在活动中调用seekBar.setEnabled(false);,以便用户无法与滑块交互。 - Damian
这正是我想在我的应用程序中实现的,我感谢您的帮助,Damian。 - japuentem

8
我认为可以使用 seekbar 实现这个动态图像,这个图像被称为拇指 drawable。

enter image description here

你可以尝试这个tutorial,它会对你很有帮助!!
将seekbar属性android:thumb="@drawable/seek_thumb"设置为所需的可绘制对象。

非常好的例子K_Anas,现在我对seekbar有了更好的了解。 - japuentem

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