Android seekbar使用九个补丁图像设置自定义样式
我正在尝试创建一个定制样式的seekbar。 我有两张九块的图片,一张是灰色的拉伸条搜索_progress.9.png(背景色),另一张是绿色的拉伸条搜索_progress _bar.9.png(前景色) 我将此xml用作我的seekbar的progressDrawable:Android seekbar使用九个补丁图像设置自定义样式,android,progress,fill,seekbar,nine-patch,Android,Progress,Fill,Seekbar,Nine Patch,我正在尝试创建一个定制样式的seekbar。 我有两张九块的图片,一张是灰色的拉伸条搜索_progress.9.png(背景色),另一张是绿色的拉伸条搜索_progress _bar.9.png(前景色) 我将此xml用作我的seekbar的progressDrawable: <?xml version="1.0" encoding="utf-8"?> <layer-list xmlns:android="http://schemas.android.com/apk/res/a
<?xml version="1.0" encoding="utf-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
<item android:id="@android:id/background" android:drawable="@drawable/search_progress"></item>
<item android:id="@android:id/progress" android:drawable="@drawable/search_progress_bar"></item>
</layer-list>
我的问题是,不是条填满了我的拇指位置,而是整个条始终是绿色的(搜索\进度\条图像)。如何使用自己的图像获得与Android的progress_horizontal.xml相同的效果(我不想使用形状来绘制条形图)?我使用ClipDrawable解决了这个问题。 这就是我的工作原理: 将@drawable/search\u progress\u drawable设置为progressDrawable 搜索\u progress\u drawable.xml:
<?xml version="1.0" encoding="utf-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
<item android:id="@android:id/background" android:drawable="@drawable/search_progress"></item>
<item android:id="@android:id/progress" android:drawable="@drawable/search_progress_clip"></item>
</layer-list>
搜索\u progress\u clip.xml:
<?xml version="1.0" encoding="utf-8"?>
<clip xmlns:android="http://schemas.android.com/apk/res/android"
android:drawable="@drawable/search_progress_bar"
android:clipOrientation="horizontal"
android:gravity="left">
</clip>
e\u x\p的版本工作正常,但更简单的版本是
<?xml version="1.0" encoding="utf-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android" >
<item android:id="@android:id/background">
<nine-patch android:src="@drawable/progressbar_bg" android:dither="true"/>
</item>
<item android:id="@android:id/progress">
<clip xmlns:android="http://schemas.android.com/apk/res/android"
android:clipOrientation="horizontal"
android:gravity="left">
<nine-patch android:src="@drawable/progressbar_status" android:dither="true"/>
</clip>
</item>
</layer-list>
当我使用九张补丁图片时,它也适用于我。谢谢