Android SeekBar thumb gets clipped/cut off

余生长醉 提交于 2019-11-27 00:42:25

问题


When using a custom thumb drawable with a SeekBar view, the thumb drawable is clipped at the left and right edges of the view.

How can I fix this behavior?


回答1:


You should be able to fix this by setting paddingLeft and paddingRight on your SeekBar to half the thumb width (remember to use density-independent units). You can also control the space allowed at the edges for a seek bar's thumb by calling setThumbOffset.




回答2:


I ran into this issue myself, and I believe the "correct" decision would be to modify android:thumbOffset as the default style for a SeekBar sets it to 8px.




回答3:


For default SeekBar I used these settings and it works fine:

android:paddingLeft="6dp"
android:paddingRight="6dp"

android:thumbOffset="8dp"



回答4:


Just for clarification.

On some places I have seen

 android:thumbOffset="8dp"

and some

android:thumbOffset="8px"

so I looked at the source code. this is the original style

<style name="Widget.SeekBar">
        <item name="android:indeterminateOnly">false</item>
        <item name="android:progressDrawable">@android:drawable/progress_horizontal</item>
        <item name="android:indeterminateDrawable">@android:drawable/progress_horizontal</item>
        <item name="android:minHeight">20dip</item>
        <item name="android:maxHeight">20dip</item>
        <item name="android:thumb">@android:drawable/seek_thumb</item>
        <item name="android:thumbOffset">8dip</item>
        <item name="android:focusable">true</item>
    </style>

from

https://android.googlesource.com/platform/frameworks/base/+/refs/heads/master/core/res/res/values/styles.xml



来源:https://stackoverflow.com/questions/2912609/android-seekbar-thumb-gets-clipped-cut-off

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