4

dividerforのスタイルを設定しようとしていListViewます。私が欲しいのは、単純な2本の水平線だけです。

list.xml

<ListView
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    style="@style/ListView" >
</ListView>

スタイル.xml

<style name="ListView" parent="android:style/Widget.ListView">
    <item name="android:divider">@drawable/divider</item>

    <!-- 5dp: just to make sure there's enough space -->
    <item name="android:dividerHeight">5dp</item>
</style>

仕切り.xml

<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
    <item>
        <shape android:shape="rectangle">
            <solid android:color="#00ffff" />
            <size android:height="1dp" />
        </shape>
    </item>
    <item>
        <shape android:shape="rectangle">
            <solid android:color="#ff0000" />
            <size android:height="1dp" />
        </shape>
    </item>
</layer-list>

height of 5dp結果は、 (2 のはずですよね?) とcolor of red(2 番目の項目の色)の横線です。色付きの最初のアイテム#00ffffはまったく表示されません。

誰かが2本の単純な水平線のコードを提案できますか?

4

1 に答える 1

11

私は自分の質問に答えたほうがいいです...

仕切り全体の背景としてstyles.xml - style - itemの色を使用last itemしているようです。layer-listこれlast item他のレイヤーの上にあるため、レイヤー リストの他の項目が表示されません。

キーはpaddingです。

スタイル.xml

<style name="ListView" parent="android:style/Widget.ListView">
    <item name="android:divider">@drawable/divider</item>
    <item name="android:dividerHeight">10dp</item>
</style>

仕切り.xml

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

    <item>
        <shape android:shape="rectangle">
            <solid android:color="#0000ff" />
            <padding android:top="5dp"/>
        </shape>
    </item>

    <item>
        <shape android:shape="rectangle">
            <solid android:color="#ff0000" />
        </shape>
    </item>

</layer-list>

分周器

したがって、私の場合、10dp/5dp を 2dp/1dp に変更して、2 つの細い水平線を取得するだけです。

于 2013-01-22T12:57:06.233 に答える