代码之家  ›  专栏  ›  技术社区  ›  vihkat

Seekbar可进行绘制Fitxy

  •  0
  • vihkat  · 技术社区  · 6 年前

    我有一个有进步能力的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" />
    

    在这个seekbar中,我使用了image.png

    enter image description here

    我手机的屏幕比这张图片大。所以我想用像“fitxy”这样的图片。

    实际上是图像的倍增。 enter image description here

    如何将图像设置为与父项匹配?

    谢谢您!

    2 回复  |  直到 6 年前
        1
  •  1
  •   Hardik Vasani    6 年前

    试试这个

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

    可拉伸文件夹 见kbar_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>
    
        2
  •  0
  •   Ufkoku    6 年前

    你可以用 9-patch 是的。

    我只是在油漆上做的,所以可能有一些错误,但希望你得到的想法。也可以使图像变小,以减小其大小。

    example.9.png