我已经自定义了我的SeekBar - 我使用自定义图像作为背景,并使用自定义图像作为拇指(How to create custom layout for seekbar in android? & How to customize the look of a SeekBar in Android?)。SeekBar自定义 - 如何正确定位自定义“拇指”图像?
的想法是做一个搜索栏,看起来像在此图像中的那些:
我希望有拇指图像完全适合圆杆时progress
值设置为0或100(满分100)。
为了正确地定位拇指(即不重叠的棒的末端)我已经设置了paddingLeft
& paddingRight
值正好一半拇指宽度(Android: Seekbar doesn't scroll all the way to end)的宽度。
.../RES /布局/ main.xml中:
<SeekBar android:id="@+id/frequency_slider"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:max="100" android:progress="0"
android:progressDrawable="@drawable/seekbar_no_visible_progress"
android:thumb="@drawable/seekbar_thumb" <!-- this is an image -->
android:background="@drawable/hos_bar" <!-- this is an image -->
android:paddingLeft="24dp"
android:paddingRight="24dp">
</SeekBar>
这个工作在Android 2.1系统。
在Android 2.2的这会产生不同的效果:
经过进一步调查(与完全默认SeekBar
尝试此我发现,拇指图像的位置已经从2.1变成了2.2,我修改paddingLeft
& paddingRight
不是问题。
- 在2.1中,拇指集中在酒吧的末端,拇指的一半放在酒吧上,一半放在酒吧外面。
- 在2.2中,拇指位于酒吧内,没有任何重叠。因此,填充值会影响结果的奇怪方式。这正是我试图实现的目标,但是当使用自定义的拇指时,这种效果不再以相同的方式工作。
我想我需要做一个自定义的Java类来处理这种类型的东西。在这个问题中(Possible to do rounded corners in custom Progressbar progressDrawable?),开发人员使用ClipDrawable
来建立一个正常的进度条。
我会使用什么类型的可绘制对象以及如何正确放置拇指?
谢谢。我更新了我的问题。我不想要的效果仍然存在(也在标准SeekBar上)。当进度值设置为0或最大值时,我希望拇指图像很好地适应条形的每个圆角端。 –