简体   繁体   English

列表视图中的分隔线

[英]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 您必须维护单独的xml文件才能显示列表视图项目,在List xml文件中,在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: 在定义列表视图的xml文件中,为分隔线高度添加另一个参数:

       <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. 这里的“ listBackground”是我在style.xml文件中定义的自定义背景。 And "listDivider" is the color for divider which I have defined in my color.xml , like this: “ listDivider”是我在color.xml中定义的分隔线的颜色,如下所示:

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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