问题描述
我制作了一个看起来像这样的自定义搜索栏
I made a customised seekbar that looks like this
问题是很难抓住滑块.所以我想要的是增加拇指的碰撞箱以使其更容易.我尝试了一些东西,但总是搞砸了搜索栏的外观.任何想法我怎么能做到这一点?
the thing is that it is pretty hard to grab the slider. so what i wanted to to is to increase the hitbox of the thumb to make it easier. i tried a few things, but always messed up the seekbar look. any ideas how i could do that?
布局.xml
<SeekBar
android:id="@+id/xxx"
style="@style/SeekBar"
android:layout_width="@dimen/pixel_130dp"
android:layout_below="@+id/name_textview"
android:layout_centerHorizontal="true" />
styles.xml
<style name="SeekBar">
<item name="android:layout_height">@dimen/pixel_20dp</item>
<item name="android:maxHeight">@dimen/pixel_20dp</item>
<item name="android:minHeight">@dimen/pixel_20dp</item>
<item name="android:thumb">@drawable/seek_bar_thumb</item>
<item name="android:paddingLeft">@dimen/pixel_5dp</item>
<item name="android:paddingRight">@dimen/pixel_5dp</item>
<item name="android:paddingTop">@dimen/pixel_2dp</item>
<item name="android:paddingBottom">@dimen/pixel_2dp</item>
<item name="android:progressDrawable">@drawable/seek_bar_progress_drawable</item>
</style>
seek_bar_thumb.xml
seek_bar_thumb.xml
<layer-list xmlns:android="http://schemas.android.com/apk/res/android" >
<item>
<shape>
<size
android:height="@dimen/pixel_16dp"
android:width="@dimen/pixel_25dp" />
<solid android:color="@android:color/transparent" />
</shape>
</item>
<item android:drawable="@drawable/slider_thumb"/>
</layer-list>
推荐答案
好吧,显然没有更聪明的方法可以做到这一点,这就是我现在所做的;我找到的唯一解决方案是在拇指图像周围添加一个透明区域.我将它的大小加倍并将 thumbOffset
参数添加到 Seekbar
.这似乎不是最好的解决方案,但至少对我来说是有效的.
Alright, since there are apparently no smarter ways to do that, here is what I did now; only solution I found was to add a transparent area around the thumb image. I doubled its size and added the thumbOffset
parameter to the Seekbar
. That doesn't seem to be the best solution, but at least it works in my case.
这篇关于使seekbar拇指hitbox更大的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!