这个形状出现在 Android Studio 上
但当它在手机上运行时,它看起来像这样
这是我的代码
在 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>
Run Code Online (Sandbox Code Playgroud)
其中@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>
Run Code Online (Sandbox Code Playgroud)
和@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>
Run Code Online (Sandbox Code Playgroud)
和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>
Run Code Online (Sandbox Code Playgroud)
任何人都可以解决这个问题,或者告诉我出了什么问题,因为我已经尝试了很多东西,但没有成功,谢谢你
图像已缩放(API 23 中添加了width和属性)。height为了避免这种情况,您可以包含一个<bitmap/>元素。
例如替换:
<item
android:width="19dp"
android:height="19dp"
android:bottom="25dp"
android:drawable="@drawable/test_small"
android:gravity="left">
</item>
Run Code Online (Sandbox Code Playgroud)
和 :
<item
android:bottom="25dp">
<bitmap
android:gravity="left"
android:src="@drawable/test_small" />
</item>
Run Code Online (Sandbox Code Playgroud)
请注意,该gravity属性位于bitmap元素上。这个技巧的解释如下:
默认情况下,所有可绘制项目都会缩放以适合包含视图的大小。因此,将图像放置在图层列表中的不同位置可能会增加视图的大小,并且某些图像会适当缩放。为了避免缩放列表中的项目,请使用
<bitmap>元素内部的元素来指定可绘制对象并将重力定义为不缩放的内容,例如 "center"。
| 归档时间: |
|
| 查看次数: |
697 次 |
| 最近记录: |