8

私は Android Listview を使用しており、リストビュー項目の両側に 1px の仕切りが必要です。これは、2 つの異なる色の上下を意味します。しかし、問題は、下部に仕切りを表示するためにログインできないことです。試してみandroid:layout_belowましたが、無効と表示されます。

これはリストビューのコードです

<ListView
        android:id="@+id/myphnview"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:layout_below="@drawable/dividerheight"
        android:background="#E9EAEC"
        android:clickable="true"
        android:divider="@drawable/dividerheight" >
    </ListView>

これは、上枠に使用している xml ファイルです。分割高さ.xml

<?xml version="1.0" encoding="utf-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android" >

    <item>
        <shape android:shape="line" >
            <stroke android:color="#c6c7c9" />

            <size android:height="1px" />
        </shape>
    </item>


</layer-list>

これは私の行のレイアウトです

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/rowlayout"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:background="#E9EAEC"
    android:orientation="horizontal" >

    <LinearLayout
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:layout_weight="2" >

        <ImageView
            android:id="@+id/icon"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_margin="5dp" 
            android:background="@drawable/ic_launcher"/>
    </LinearLayout>

    <LinearLayout
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:layout_marginTop="10dp"
        android:layout_weight="1" >

        <TextView
            android:id="@+id/file_name"
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:layout_gravity="left"
            android:layout_margin="5dp"
            android:text="Hello Android "
            android:textColor="@android:color/black"
            android:textSize="20dp" >
        </TextView>
    </LinearLayout>

    <LinearLayout
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_margin="5dp" >

        <ImageView
            android:id="@+id/share_button"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_gravity="left"
            android:background="@drawable/ic_launcher"/>
    </LinearLayout>



</LinearLayout>
4

3 に答える 3

18

これを実現するにはいくつかの方法があります。簡単な方法の 1 つは、リスト内の仕切りを完全に非表示にし (仕切りの幅を 0 に設定するか、仕切りを null に設定し)、各リスト項目に上部に 1 行、下部に 1 行を含めることです。次の xml を検討してください。

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="60dp">

    <View
        android:layout_width="match_parent"
        android:layout_height="1dp"
        android:layout_alignParentTop="true"
        android:background="@android:color/white" />

    <LinearLayout ...>
        <!-- this is your current list item LinearLayout -->
    </LinearLayout>

    <View
        android:layout_width="match_parent"
        android:layout_height="1dp"
        android:layout_alignParentBottom="true"
        android:background="@android:color/black" />

</RelativeLayout>

getView既にカスタム アダプターを使用しているため、アダプターのメソッドでリスト アイテムのレイアウトに上記のような XML を使用するだけです。これにより、高さ 60 dp のリスト アイテムが生成され、上部に白い線があり、下部に黒い線があります。

于 2013-04-23T11:16:25.410 に答える
2

これを行う方法はないと思います。footerviewただし、とを追加できheaderviewますListView。欲しいものが届くと思います。

例えば:

TextView tv1 = new Textview(this);
tv1.setBackgroundResource(R.drawable.dividerheight);

listview.addHeaderView(totalExpense);
listview.addFooterView(totalExpense);

これがお役に立てば幸いです。

于 2013-04-23T11:03:16.810 に答える