求进度条Drawable Expand
Seek bar progress Drawable Expand
您好,我想制作如下所示的自定义搜索栏
这个形状出现在 Android Studio
但是当它 运行 在 Phone 上时它看起来像这样
这是我的代码
在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>
谁能解决这个问题,或者告诉我哪里出了问题,因为我已经尝试了很多方法但都没有用
谢谢你
图像已缩放(width
和 height
属性已添加到 API 23)。为避免这种情况,您可以包含一个 <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 Studio
但是当它 运行 在 Phone 上时它看起来像这样
这是我的代码
在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>
谁能解决这个问题,或者告诉我哪里出了问题,因为我已经尝试了很多方法但都没有用 谢谢你
图像已缩放(width
和 height
属性已添加到 API 23)。为避免这种情况,您可以包含一个 <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".