简体   繁体   中英

Divider in listview

在我的应用程序中,我正在列表视图中显示数据库中的数据。列表视图就像显示2列。现在我想在这2个之间绘制一条水平线以显示2列是分开的。请帮助我。预先。

You have to maintain seperate xml file for showing list view items, In the List xml file use this horizontal and vertical views in between textViews

so for horizontal divider use this code

     <View 
          android:id="@+id/View01"
          android:layout_width="fill_parent"
          android:layout_height="2dp"
          android:background="#2B497B"
        />

and for vertical divider

         <View 
          android:id="@+id/View02"
          android:layout_width="2dip"
          android:layout_height="fill_parent"
          android:background="#2B497B"
        />

Good luck

在此处输入图片说明

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="horizontal" >


<LinearLayout 
        android:layout_weight="0.3"
        android:orientation="vertical"
        android:layout_width="0dp"
        android:layout_height="fill_parent">

         <TextView 
             android:padding="2dp"
             android:id="@+id/nameedit"
             android:textSize="15dp"
             android:layout_height="40dp"
             android:layout_width="fill_parent"
             android:layout_gravity="center"
             android:text="@string/search">
        </EditText>
         <View 
          android:id="@+id/View01"
          android:layout_width="fill_parent"
          android:layout_height="2dp"
          android:background="#2B497B"
        />
<TextView 
             android:id="@+id/header"
             android:layout_height="40dp"
             android:layout_width="fill_parent"
             android:textColor="#fff"
             android:textSize="15dp"
             android:gravity="center"
             android:text="@string/reports"/>
        <!-- <ListView android:id="@+id/namelist"
        android:cacheColorHint="#00000000"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:fadingEdge="none">
        </ListView> -->

    </LinearLayout>
    <View 
          android:id="@+id/View02"
          android:layout_width="2dip"
          android:layout_height="fill_parent"
          android:background="#2B497B"
        />

    <LinearLayout 
        android:layout_weight="0.7"
        android:orientation="vertical"
        android:layout_width="0dp"
        android:layout_height="fill_parent">

         <TextView 
             android:id="@+id/header"
             android:layout_height="40dp"
             android:layout_width="fill_parent"
             android:textColor="#fff"
             android:textSize="15dp"
             android:gravity="center"
             android:text="@string/reports"/>
         <View 
          android:id="@+id/View03"
          android:layout_width="fill_parent"
          android:layout_height="2dp"
          android:background="#2B497B"
        />

        <!-- <ListView android:id="@+id/reportslist"
        android:cacheColorHint="#00000000"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content" 
        android:fadingEdge="none"/> -->
        <TextView 
             android:id="@+id/header"
             android:layout_height="40dp"
             android:layout_width="fill_parent"
             android:textColor="#fff"
             android:textSize="15dp"
             android:gravity="center"
             android:text="@string/reports"/>

    </LinearLayout>

In your xml file where you are defining your listview, add one more parameter for the divider height:

       <ListView
            android:layout_marginTop="10dip"  
            android:layout_width="fill_parent" 
            android:layout_height="fill_parent"
            android:divider="@color/listDivider"
            android:dividerHeight="1dp"
            android:footerDividersEnabled="false"
            android:headerDividersEnabled="true"
            style="@style/listBackground" 
            android:id="@+id/list"/>

Here "listBackground" is the custom background which I have defined in my style.xml file. And "listDivider" is the color for divider which I have defined in my color.xml , like this:

       <color name="listDivider">#cfcfcf</color>

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM