自定义搜索栏绘制对象的Andr​​oid自定义、对象、oid、Andr

2023-09-06 13:49:41 作者:黑色:纪念日

我要到默认的Andr​​oid搜索栏个性化设置:

I want to personalise the default Android seekbar to:

我看了大约九标图像,创造了6 PNG图像。前三个都为灰色进度条(progressDrawable),如下所示:

I read about nine patch image and created 6 png images. The first three are for the gray progress bar (progressDrawable), as shown below:

右图像

Right image

图片中心

左图

结果应该是:

蓝色图像重新present的进展,并如下:

The blue images represent the progress and are as follows:

右图像

Right image

图片中心

左图

和拇指如下:

我的问题是,我该如何使用9片图像生成自定义搜索栏完全按照第一张照片,我怎么可以把这个给我的搜索栏?

My question is, how can I use nine patch image to generate the custom seekbar exactly as the first picture and how can I apply this to my seekbar?

推荐答案

我觉得这不应该是复杂的。你不必做6幅以满足您的需求。只要创建2九补丁背景,进展。而thumb.png。这是你的XML:

I think it shouldn't be complex. You don't have to make 6 images to fulfill your needs. Just create 2 nine-patches for background, progress. And thumb.png. Here is your XML:

<SeekBar
  android:id="@+id/my_seekbar"
  android:layout_width="wrap_content"
  android:layout_height="wrap_content"
  android:progressDrawable="@drawable/seekbar_progress"
  android:thumb="@drawable/thumb">

seekbar_progress

 <?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>

请记住,你的拇指应该创造这样它看起来像你想的时候都在上面空白处。 希望这有助于。

Do remember that your thumb should have blank space on top when creating so it looks like you wanted. Hope this helps.