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