Layout_below 在我的列表视图中不起作用

Layout_below is not working in my listview

我有自定义工具栏,我希望我的列表视图位于 Toolbar 下方。但是列表视图出现在工具栏上,而我的 layout_below 不工作。我知道之前已经问过很多问题。但没有任何效果。请帮助我

下面是我的layoutxml

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

tools:context="faisal.home.com.tafaqquhfiddin.DuwaListView">

<include
    layout="@layout/toolbar_layout"
    />

<ListView
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:id="@+id/MyListView"
    android:layout_below="@+id/toolbar"
   ></ListView>

</RelativeLayout>

toolbarlayout.xml

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

<android.support.v7.widget.Toolbar    
xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    android:id="@+id/toolbar"
    android:layout_width="match_parent"
    android:layout_height="?attr/actionBarSize"
    android:background="@color/orange"
    app:layout_scrollFlags="scroll|enterAlways"
    app:titleTextColor="@color/white"></android.support.v7.widget.Toolbar>

</LinearLayout>

从您的 toolbarlayout.xml 中删除 LinearLayout。所以你的 toolbarlayout.xml 应该是这样的:

<android.support.v7.widget.Toolbar    
xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    android:id="@+id/toolbar"
    android:layout_width="match_parent"
    android:layout_height="?attr/actionBarSize"
    android:background="@color/orange"
    app:layout_scrollFlags="scroll|enterAlways"
    app:titleTextColor="@color/white"></android.support.v7.widget.Toolbar>

问题已被其他用户回答...

我想补充更多信息。

您的布局可以简单得多。您不需要使用 RelativeLayout。只需使用 LinearLayoutandroid:orientation="vertical" 即可。这样,您将拥有:

layout.xml

<LinearLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical"
    tools:context="faisal.home.com.tafaqquhfiddin.DuwaListView">

    <include
        layout="@layout/toolbar_layout"/>

    <ListView
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:id="@+id/MyListView" />

</LinearLayout>

工具栏布局

<android.support.v7.widget.Toolbar
    xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    android:id="@+id/toolbar"
    android:layout_width="match_parent"
    android:layout_height="?attr/actionBarSize"
    app:layout_scrollFlags="scroll|enterAlways"
    android:background="@color/orange"
    app:titleTextColor="@color/white" />

使用下面的代码就可以了。

我的layoutxml

   <?xml version="1.0" encoding="utf-8"?>
    <LinearLayout 
    xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical"
    tools:context="faisal.home.com.tafaqquhfiddin.DuwaListView">

    <include
        layout="@layout/toolbar_layout"
        />

    <ListView
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:id="@+id/MyListView"
        android:layout_below="@+id/toolbar"
       ></ListView>

</LinearLayout >

toolbarlayout.xml 高度的根布局是 "match_parent" 将其更改为 "wrap_content"。使用下面的代码它会起作用。

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
tools:context="faisal.home.com.tafaqquhfiddin.DuwaListView">

<include
    layout="@layout/toolbar_layout"/>

<ListView
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:id="@+id/MyListView"
    android:layout_below="@+id/toolbar"/>
</LinearLayout>

toolbarlayout.xml

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

<android.support.v7.widget.Toolbar    
xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    android:id="@+id/toolbar"
    android:layout_width="match_parent"
    android:layout_height="?attr/actionBarSize"
    android:background="@color/orange"
    app:layout_scrollFlags="scroll|enterAlways"
    app:titleTextColor="@color/white"/>

</LinearLayout>