2011-08-21 12 views
9

カスタムスタイルのシークバーを作成しようとしています。 2つの9パッチ画像があります。一方は灰色のストレッチバーですsearch_progress.9.png(背景色)ともう一方は緑色のストレッチバーsearch_progress_bar.9.png(前景色)です。Androidシークバーは9パッチ画像を使用してカスタムスタイルを設定しました

は、私は私のシークバーのprogressDrawableとしてこの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_bar"></item> 
</layer-list> 

私の問題ではなく、私の親指の位置まで充填バーの、全体のバーは、すべての時間(search_progress_barイメージ)緑である、ということです。自分の画像を使ってAndroidのprogress_horizo​​ntal.xmlと同じ効果を得るにはどうすればよいですか(私のバーを描くにはシェイプを使用したくありません)?

答えて

11

私はこの問題をClipDrawableを使って解決しました。 これは私のために働いたものです:

@ drawable/search_progress_drawableをprogressDrawableに設定します。

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

search_progress_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> 
16

e_x_pのバージョンはうまく動作しますが、より簡単なバージョンが

1でそれをすべて保つためにニース
<?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> 
+0

ですファイル、ありがとう! – Russ

+1

は魅力的に機能します! :) – yahya

+0

私は9つのパッチ画像を使用しているが、それは私の仕事でもある。ありがとう! – Hasmukh

関連する問題