[英]Android SeekBar thumb gets clipped/cut off
When using a custom thumb drawable with a SeekBar
view, the thumb drawable is clipped at the left and right edges of the view.在
SeekBar
视图中使用自定义拇指可绘制时,拇指可绘制在视图的左右边缘被剪裁。
How can I fix this behavior?我该如何解决这种行为?
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).您应该能够通过将
SeekBar
上的paddingLeft
和paddingRight
设置为拇指宽度的一半来解决此问题(请记住使用与密度无关的单位)。 You can also control the space allowed at the edges for a seek bar's thumb by calling setThumbOffset
.您还可以通过调用
setThumbOffset
来控制搜索栏拇指边缘允许的空间。
我自己遇到了这个问题,我相信"correct"
决定是修改android:thumbOffset
作为SeekBar的默认样式将其设置为 8px。
For default SeekBar I used these settings and it works fine:对于默认的 SeekBar,我使用了这些设置并且它工作正常:
android:paddingLeft="6dp"
android:paddingRight="6dp"
android:thumbOffset="8dp"
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://android.googlesource.com/platform/frameworks/base/+/refs/heads/master/core/res/res/values/styles.xml
I was getting the bottom of my default seekbar thumb clipped.我的默认搜索栏拇指的底部被剪掉了。 None of the fixes here worked.
这里没有任何修复工作。 I ended up using
我最终使用
android:clipToPadding="false"
on the parent view.在父视图上。 This solved issue.
这解决了问题。
<androidx.appcompat.widget.AppCompatSeekBar
android:id="@+id/progress_loan_period"
android:layout_width="@dimen/dp_0"
android:layout_height="wrap_content"
android:layout_marginTop="@dimen/dp_15"
android:progressDrawable="@drawable/seek_bar"
android:thumb="@drawable/ic_slider"
android:paddingStart="@dimen/dp_0"
android:paddingEnd="@dimen/dp_0"
android:thumbOffset="-0dp"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintTop_toBottomOf="@id/label_loan_period" />
This gets the job done这可以完成工作
没有什么对我有用,但我只是改变了拇指的颜色,而不是父布局的背景颜色,它对我有用。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.