其他分享
首页 > 其他分享> > 寻求进度条Drawable展开

寻求进度条Drawable展开

作者:互联网

嗨,我想制作自定义搜索栏,看起来像这样
enter image description here

这个形状出现在Android Studio上

但是当它在手机上运行时,它看起来像这样

enter image description here

这是我的代码

在XML中

<LinearLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content">
        <SeekBar
            android:id="@+id/seekBar"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_marginTop="10dp"
            android:max="10000"
            android:progress="500"
            android:progressDrawable="@drawable/custom_seekbar"
            android:thumb="@drawable/thumb_transperent"
            />
    </LinearLayout>

其中@ drawable / custom_seekbar

<layer-list xmlns:android="http://schemas.android.com/apk/res/android">

    <!-- Define the background properties like color etc -->

    <item android:id="@android:id/background">
        <rotate>
            <layer-list>
                <item android:drawable="@drawable/progress_bar"/>
            </layer-list>
        </rotate>
    </item>

    <!-- Define the progress properties like start color, end color etc -->
    <item android:id="@android:id/progress">
        <clip>
            <layer-list>
                <item android:drawable="@drawable/progressbar_progress"/>
            </layer-list>
            </clip>
    </item>
</layer-list>

和@ drawable / progress_bar

<?xml version="1.0" encoding="utf-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
    <item
        android:top="15dp">
        <shape android:shape="line">
            <stroke android:color="@color/black"
                android:width="5dp"/>
            <solid android:color="@android:color/transparent" />
        </shape>
    </item>

    <item
        android:bottom="25dp"
        android:left="0dp"
        android:right="100dp"
        android:gravity="left"

        android:drawable="@drawable/test_small">

    </item>
    <item
        android:left="50dp"
        android:right="50dp"
        android:bottom="25dp"
        android:gravity="center"

        android:drawable="@drawable/test_meduim">

    </item>
    <item
        android:left="100dp"
        android:bottom="25dp"
        android:gravity="right"
        android:drawable="@drawable/test_large">

    </item>
</layer-list>

和progressbar_progress

<?xml version="1.0" encoding="utf-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
    <item android:top="15dp">
        <shape android:shape="line">

            <solid android:color="@android:color/transparent" />
            <stroke android:color="@color/red" android:width="3dp"/>
        </shape>
    </item>

    <item
        android:bottom="25dp"
        android:gravity="left"
        android:width="19dp"
        android:height="19dp"
        android:drawable="@drawable/test_small">

    </item>

    <item
        android:gravity="center"
        android:right="12dp"
        android:bottom="25dp"
        android:width="19dp"
        android:height="19dp"
        android:drawable="@drawable/test_meduim">

    </item>
    <item
        android:bottom="25dp"
        android:gravity="right"
        android:width="19dp"
        android:height="19dp"
        android:drawable="@drawable/test_large">

    </item>
</layer-list>

任何人都可以解决这个问题或告诉我什么错误的原因吗?我尝试了很多东西而没有工作
然后打你

解决方法:

缩放图像(在API 23中添加了width和height属性).为避免这种情况,您可以添加< bitmap />元件.

例如替换:

<item
    android:width="19dp"
    android:height="19dp"
    android:bottom="25dp"
    android:drawable="@drawable/test_small"
    android:gravity="left">

</item>

与:

<item
    android:bottom="25dp">
    <bitmap
        android:gravity="left"
        android:src="@drawable/test_small" />
</item>

请注意,gravity属性位于位图元素上.
技巧解释为here

All drawable items are scaled to fit the size of the containing View,
by default. Thus, placing your images in a layer list at different
positions might increase the size of the View and some images scale as
appropriate. To avoid scaling items in the list, use a <bitmap>
element inside the element to specify the drawable and define
the gravity to something that does not scale, such as “center”
.

标签:seekbar,android
来源: https://codeday.me/bug/20191025/1927150.html