Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/204.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/xml/13.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Android 查看行未显示在item.xml中的原因_Android_Xml - Fatal编程技术网

Android 查看行未显示在item.xml中的原因

Android 查看行未显示在item.xml中的原因,android,xml,Android,Xml,我刚刚为列表视图项创建了一个项XML,我假设它创建了两个视图,一个在列表项的顶部,另一个在列表项的底部。 这是我的XML文件: <?xml version="1.0" encoding="utf-8"?> <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:app="http://schemas.android.com/apk/res-auto" and

我刚刚为列表视图项创建了一个项XML,我假设它创建了两个视图,一个在列表项的顶部,另一个在列表项的底部。 这是我的XML文件:

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    android:id="@+id/rlo"
    android:layout_width="match_parent"
    android:layout_height="40dp"
    android:orientation="vertical">

    <View
        android:id="@+id/line1"
        android:layout_width="fill_parent"
        android:layout_height="1dp"
        android:layout_alignParentTop="true"
        android:background="#737373" />

    <TextView
        android:id="@+id/username62"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_centerHorizontal="true"
        android:layout_centerVertical="true"
        android:text="yassin elhadedy"
        android:textSize="15dp"
        android:textStyle="bold" />

    <View
        android:id="@+id/line2"
        android:layout_width="match_parent"
        android:layout_height="1dp"
        android:layout_below="@+id/username62"
        android:layout_marginTop="21dp"
        android:background="#737373" />
</RelativeLayout>

它显示如下:

运行project时未显示id为/line的此行。
对于这种情况,我能做些什么?

您好,您可以通过标准API实现这一点,如果您使用的是RecyclerView,而不是添加项目行分隔符,则可以使用此代码

DividerItemDecoration mDividerItemDecoration = new DividerItemDecoration(recyclerView.getContext(),
             mLayoutManager.getOrientation());
     recyclerView.addItemDecoration(mDividerItemDecoration);
如果您使用的是ListView,那么只需使用下面的代码即可

 <ListView 
    android:id="@+id/ListView01" 
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:divider="@color/redBackground"
    android:dividerHeight="1dip">
 </ListView>


您使用的是recyclerView还是ListView?@Alok我使用的是ListView非常感谢@Alok您帮助了我但很抱歉@Alok我如何解决DividerItemDecoration?使用此链接了解更多详细信息和