简体   繁体   English

在Appbar下方设置Recyclerview

[英]Set Recyclerview below Appbar

I want to set an appbar in my activity_main. 我想在我的activity_main中设置一个应用栏。 For some reason, I am not able to set it properly. 由于某些原因,我无法正确设置。 It is being set below the recycler view. 它被设置在回收站视图下方。

Here is my activity_main 这是我的activity_main

 <?xml version="1.0" encoding="utf-8"?> <android.support.v4.widget.DrawerLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:app="http://schemas.android.com/apk/res-auto" xmlns:tools="http://schemas.android.com/tools" android:id="@+id/drawer_layout" android:layout_width="match_parent" android:layout_height="match_parent" android:fitsSystemWindows="true" tools:openDrawer="start"> <include layout="@layout/app_bar_main" android:layout_width="match_parent" android:layout_height="wrap_content" /> <RelativeLayout android:layout_width="match_parent" android:layout_height="match_parent" android:orientation = "vertical" android:layout_marginTop="?attr/actionBarSize" tools:context=".MainActivity"> <android.support.v7.widget.RecyclerView android:id="@+id/recyclerview_heritage_sites" android:layout_width="match_parent" android:layout_height="wrap_content" android:scrollbars="vertical"/> </RelativeLayout> </android.support.v4.widget.DrawerLayout> 

Here is my app_bar_main 这是我的app_bar_main

 <?xml version="1.0" encoding="utf-8"?> <android.support.design.widget.CoordinatorLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:app="http://schemas.android.com/apk/res-auto" xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent" android:layout_height="match_parent" tools:context=".MainActivity"> <android.support.design.widget.AppBarLayout android:layout_width="match_parent" android:layout_height="wrap_content" android:theme="@style/AppTheme.AppBarOverlay"> <android.support.v7.widget.Toolbar android:id="@+id/toolbar" android:layout_width="match_parent" android:layout_height="?attr/actionBarSize" android:background="@color/colorWhite" app:popupTheme="@style/AppTheme.PopupOverlay" /> </android.support.design.widget.AppBarLayout> </android.support.design.widget.CoordinatorLayout> 

Thank you for your time and help! 感谢您的时间和帮助!

<?xml version="1.0" encoding="utf-8"?>

<android.support.v4.widget.DrawerLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools"
    android:id="@+id/drawer_layout"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:fitsSystemWindows="true"
    tools:openDrawer="start">

    <RelativeLayout
        android:layout_width="match_parent"
        android:layout_height="match_parent">

         <include
             android:id="@+id/appbar"
             layout="@layout/app_bar_main"
             android:layout_width="match_parent"
             android:layout_height="wrap_content" />

         <RelativeLayout
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:layout_marginTop="?attr/actionBarSize"
            android:layout_below="@id/appbar"
            tools:context=".MainActivity">

            <android.support.v7.widget.RecyclerView
                android:id="@+id/recyclerview_heritage_sites"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:scrollbars="vertical"/>

        </RelativeLayout>
    </RelativeLayout>


</android.support.v4.widget.DrawerLayout>

You can use LinearLayout : 您可以使用LinearLayout

<?xml version="1.0" encoding="utf-8"?>
<android.support.v4.widget.DrawerLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools"
    android:id="@+id/drawer_layout"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:fitsSystemWindows="true"
    tools:openDrawer="start">

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:orientation="vertical">

        <include
            layout="@layout/app_bar_main"
            android:layout_width="match_parent"
            android:layout_height="wrap_content" />

        <RelativeLayout
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:orientation = "vertical"
            android:layout_marginTop="?attr/actionBarSize"
            tools:context=".MainActivity">

            <android.support.v7.widget.RecyclerView
                android:id="@+id/recyclerview_heritage_sites"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:scrollbars="vertical"/>

        </RelativeLayout>

    </LinearLayout>

</android.support.v4.widget.DrawerLayout>

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

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