gpt4 book ai didi

android - 求进度条Drawable Expand

转载 作者:太空宇宙 更新时间:2023-11-03 13:09:14 28 4
gpt4 key购买 nike

嗨,我想制作看起来像这样的自定义搜索栏 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 中添加了 widthheight 属性)。为避免这种情况,您可以包含 <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属性在 bitmap 上元素。技巧解释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".

关于android - 求进度条Drawable Expand,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49715500/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com