Make seekbar thumb hitbox bigger

大兔子大兔子 提交于 2019-12-08 01:15:44

问题


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?

layout.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

<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>

回答1:


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.




回答2:


The TouchDelegate class seems to be a good place to start.

See this tutorial on how you can use it.



来源:https://stackoverflow.com/questions/21005319/make-seekbar-thumb-hitbox-bigger

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!