我想默認的Android搜索條個性化設置:自定義搜索欄繪製對象的Android
我看了大約九補丁圖像,創造了6個PNG圖像。前三個是爲灰進度條(progressDrawable),如下圖所示:
右圖像
中心圖像
左圖像
結果應該是:
藍色圖像表示的進展,並如下:
右圖像
中心圖像
左圖
和拇指如下:
我的問題是,我該如何使用9個修補圖像生成自定義搜索條完全一樣的第一張照片,我怎麼能將此我的搜索條?
我想默認的Android搜索條個性化設置:自定義搜索欄繪製對象的Android
我看了大約九補丁圖像,創造了6個PNG圖像。前三個是爲灰進度條(progressDrawable),如下圖所示:
右圖像
中心圖像
左圖像
結果應該是:
藍色圖像表示的進展,並如下:
右圖像
中心圖像
左圖
和拇指如下:
我的問題是,我該如何使用9個修補圖像生成自定義搜索條完全一樣的第一張照片,我怎麼能將此我的搜索條?
我認爲它不應該是複雜的。您不必製作6張圖片即可滿足您的需求。只需爲背景創建2個九塊補丁即可。和thumb.png。這裏是你的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>
請記住,創造,所以它看起來像你想,當你thumb
應該對上面的空白。 希望這有助於。
1)進入AndroidSDK - >工具和運行draw9patch.bat
,你會看到黑色窗口
2)拖動圖片到窗口,並開始9補丁:
圍繞你的圖片開始打補丁
3)現在進入文件菜單並且點擊保存9補丁...
最後提示:您的圖片必須是。PNG格式,並且只包含內容而不是可用空間。例如我把你的照片保存在我的電腦裏,看到你的照片的藍色部分有很多未使用的空間。
現在應用到你的搜索條:
只要按照上面的鏈接以及
對不起;我沒有足夠的信譽來插入圖片
您可以使用Java代碼自定義seekbar ...並添加圖層列表作爲drawables ...這段代碼將幫助我,我希望。
1.LayerList繪製
<layer-list
xmlns:android="http://schemas.android.com/apk/res/android">
<item
android:id="@android:id/background">
<nine-patch
android:src="@drawable/your_nine_patch_image"
android:tileMode="repeat">
</nine-patch>
</item>
<item
android:id="@android:id/progress">
<layer-list
xmlns:android="http://schemas.android.com/apk/res/android" >
<item>
<clip >
<bitmap
xmlns:android="http://schemas.android.com/apk/res/android"
android:src="@drawable/clipimage_for_progress"
android:tileMode="repeat"/>
</clip>
</item>
</layer-list>
</item>
</layer-list>
這將是你customSeekbar類,你可以使用此自定義搜索條在你的應用
public class CustomSeekbar {
public CustomSeekbar(Context context) {
super(context);
setCustomUI();
}
public CustomSeekbar(Context context, AttributeSet attrs) {
super(context, attrs);
setCustomUI();
}
public CustomSeekbar(Context context, AttributeSet attrs, int defStyle) {
super(context, attrs, defStyle);
setCustomUI();
}
void setCustomUI() {
this.setProgressDrawable(getResources().getDrawable(
R.drawable.yourBackground));
}
}
我建議你檢查由框架本身使用的可繪。你可以在你的android sdk目錄中找到它們:'android-sdk-dir/platforms/platform-XX/data/res/drawable- * dpi'。查找名爲scrubber_track * .9.png,scrubber_primary * .9.png,scrubber_secondary * .9.png和scrubber_control * .9.png(*爲通配符)的九個補丁映像 – Karakuri
您能否提供給我一個示例請 – Dimitri
你可以將圖像1,2和3合併成一個可繪製的九個修補程序 – pskink