首页 > 解决方案 > 如果“高度”设置为 2dp 或低于“wrap_content”,SeekBar 不显示完整的“拇指图标”

问题描述

在我的应用程序中,我使用带有自定义“拇指图标”和自定义“颜色”的 SeekBar。根据要求,我将其高度设置为 2dp,但在这种情况下,SeekBar 未显示完整的“拇指图标”,当我将其高度设置为“wrap_content”时,它显示完整的“拇指图标”,但它也增加了进度线高度超出预期。下面是清楚地解释我的问题的图像,请检查 -

在此处输入图像描述

下面是我的xml代码——

activity_seek_bar.xml

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:background="@android:color/white"
    android:layout_height="match_parent"
    tools:context=".Activity.SeekBarTestActivity">

    <SeekBar
        android:id="@+id/seekBar1"
        android:layout_width="match_parent"
        android:thumb="@drawable/sb_pointer"
        android:splitTrack="false"
        android:progress="50"
        android:progressDrawable="@drawable/progress_drawable"
        android:layout_height="wrap_content"
        android:layout_marginTop="90dp" />

</RelativeLayout>

progress_drawable.xml

<?xml version="1.0" encoding="utf-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
    <item android:id="@android:id/background">
        <shape>
            <solid
                android:color="#3a3a3a" />
        </shape>
    </item>

    <item
        android:id="@android:id/progress">
        <clip>
            <shape>
                <solid
                    android:color="@color/media_action_color" />
            </shape>
        </clip>
    </item>

</layer-list>

我做了很多谷歌搜索,但不幸的是到目前为止没有结果,这就是为什么我需要你们专家的一些指导。另外,请让我知道我是否可以提供更多详细信息。谢谢你。

标签: androidseekbarandroid-seekbarandroid-seek

解决方案


use

    android:layout_height="wrap_content"
    android:maxHeight="2dp"

推荐阅读