9

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

この xml をシークバーの progressDrawable として使用します。

<?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 と同じ効果を得るにはどうすればよいですか (図形を使用してバーを描画したくありません)。

4

2 に答える 2

16

e_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>
于 2012-06-19T05:37:05.377 に答える
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>
于 2011-08-26T06:33:10.397 に答える