首页 > 解决方案 > SeekBar progressDrawable fitXY

问题描述

我有一个带有progressDrawable 的SeekBar。

<SeekBar
    android:id="@+id/seekbar"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:layout_marginBottom="8dp"
    android:layout_marginTop="8dp"
    android:progress="50"
    android:progressDrawable="@drawable/image"
    app:layout_constraintBottom_toBottomOf="parent"
    app:layout_constraintTop_toTopOf="parent" />

在这个搜索栏中,我使用了 image.png

在此处输入图像描述

我的手机屏幕比这张图大。所以我想像“fitXY”一样使用这个图像。

实际上它是乘以图像。 在此处输入图像描述

如何将图像设置为 match_parent?

谢谢 !

标签: androidandroid-seekbar

解决方案


试试这个

<SeekBar
        android:id="@+id/seekbar"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_marginBottom="8dp"
        android:layout_marginTop="8dp"
        android:progress="50"
        android:progressDrawable="@drawable/seekbar_bg"
        app:layout_constraintBottom_toBottomOf="parent"
        app:layout_constraintTop_toTopOf="parent" />

Drawble 文件夹 seekbar_bg.xml

<?xml version="1.0" encoding="utf-8"?>
    <layer-list xmlns:android="http://schemas.android.com/apk/res/android" >
        <item
            android:left="300dip">
            <shape
                xmlns:android="http://schemas.android.com/apk/res/android"
                android:shape="rectangle" >
                <solid android:color="#0000FF" />
            </shape>
        </item>
        <item android:right="400dip">
            <shape
                xmlns:android="http://schemas.android.com/apk/res/android"
                android:shape="rectangle" >
                <solid android:color="#ff0000" />
            </shape>
        </item>

    </layer-list>

推荐阅读