2013-09-21 12 views
0

我想用自定義seekbar裏面有數字尺度,但是不工作。該搜索欄必須支持所有屏幕分辨率。我怎麼能這樣做。請給出您的寶貴意見。如何在android seekbar中添加數字縮放?

我custom_seekbar.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/unselect"/> 
<item 
    android:id="@android:id/secondaryProgress" 
    android:drawable="@drawable/select"> 
</item> 
<item 
    android:id="@android:id/progress" 
    android:drawable="@drawable/select"> 
</item> 

activity_main.xml中

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
xmlns:tools="http://schemas.android.com/tools" 
android:layout_width="match_parent" 
android:layout_height="match_parent" 
android:background="@color/default_screen_bg" 
android:orientation="vertical" 
tools:context=".MainActivity" > 



<SeekBar 
    android:id="@+id/seekBar1" 
    android:layout_width="match_parent" 
    android:layout_height="wrap_content" 
    android:layout_margin="10dp" 
    android:indeterminate="false" 
    android:max="10" 
    android:paddingLeft="15dp" 
    android:paddingRight="15dp" 
    android:progressDrawable="@drawable/custom_seekbar" /> 

</LinearLayout> 

Unselesct.png

enter image description here

select.png

enter image description here

myresult屏幕這樣

enter image description here

我期待這樣的

enter image description here enter image description here enter image description here enter image description here

+0

你的意思是'不工作'是什麼意思?什麼是可繪製/取消選擇等圖像?這些圖像顯示不正確嗎? – sandrstar

+0

@sandrstar是的。選擇和取消選擇圖像不能正確顯示 –

回答

1

有號碼,以解決問題的方法:

  • 爲backgorund使用9patch圖像(這基本上是應該作爲背景搜索條)。如下所示:

enter image description here(名稱應爲unselect_patch.9.png),並稍微修改custom_seekbar.xml看起來像下面這樣:

<layer-list xmlns:android="http://schemas.android.com/apk/res/android" > 

    <item 
     android:id="@android:id/background" 
     android:drawable="@drawable/unselect_patch"/> 
    <item android:id="@android:id/secondaryProgress"> 
     <clip> 
      <bitmap xmlns:android="http://schemas.android.com/apk/res/android" 
       android:src="@drawable/select" 
       android:tileMode="disabled" /> 
     </clip> 
    </item> 
    <item android:id="@android:id/progress"> 
     <clip> 
      <bitmap xmlns:android="http://schemas.android.com/apk/res/android" 
       android:src="@drawable/select" 
       android:tileMode="disabled" /> 
     </clip> 
    </item> 

</layer-list> 

enter image description here

  • 只需提供佈局圖像的確切大小(例如layout_width="@dimen/select_image_width");

支持所有分辨率 - 提供不同分辨率的圖像,如Supporting Multiple Screens中所述。相同的圖像對於所有分辨率都無法正常工作,這裏最好只遵循上面鏈接中詳細描述的最佳做法。

+0

@sandrstar可以幫助我,如果我想從1到142的數字,那麼我可能需要把圖像必須包含數字從1到142或有任何方法可以繪製像線條和數字使用onDraw(),應該產生像上面那樣的最終圖像 – Erum

+0

@ErumHannan不,沒有這樣的方法,如果你需要自定義繪製,那麼seek bar應該被擴展並且onDraw()掛鉤。 – sandrstar

+0

@sandrstar你可以幫我解決這個問題.....我將如何繪製我可能需要採取任何循環顯示的比例尺像線,直到4,然後第5行應該足夠大,再次4行 – Erum