繁体   English   中英

Android SeekBar 拇指被剪裁/切断

[英]Android SeekBar thumb gets clipped/cut off

SeekBar视图中使用自定义拇指可绘制时,拇指可绘制在视图的左右边缘被剪裁。

我该如何解决这种行为?

您应该能够通过将SeekBar上的paddingLeftpaddingRight设置为拇指宽度的一半来解决此问题(请记住使用与密度无关的单位)。 您还可以通过调用setThumbOffset来控制搜索栏拇指边缘允许的空间。

我自己遇到了这个问题,我相信"correct"决定是修改android:thumbOffset作为SeekBar的默认样式将其设置为 8px。

对于默认的 SeekBar,我使用了这些设置并且它工作正常:

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

android:thumbOffset="8dp"

只是为了澄清。

在我见过的一些地方

 android:thumbOffset="8dp"

还有一些

android:thumbOffset="8px"

所以我查看了源代码。 这是原来的风格

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

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

我的默认搜索栏拇指的底部被剪掉了。 这里没有任何修复工作。 我最终使用

     android:clipToPadding="false"

在父视图上。 这解决了问题。

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

这可以完成工作

没有什么对我有用,但我只是改变了拇指的颜色,而不是父布局的背景颜色,它对我有用。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM