Android 在Appbar下面设置Recyclerview
我想在我的activity_main中设置一个appbar。由于某种原因,我无法正确设置它。它被设置在“回收器”视图下方 这是我的主要活动Android 在Appbar下面设置Recyclerview,android,android-layout,android-recyclerview,android-relativelayout,Android,Android Layout,Android Recyclerview,Android Relativelayout,我想在我的activity_main中设置一个appbar。由于某种原因,我无法正确设置它。它被设置在“回收器”视图下方 这是我的主要活动 您可以使用LinearLayout: <?xml version="1.0" encoding="utf-8"?> <android.support.v4.widget.DrawerLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:ap
您可以使用
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>
谢谢!它起作用了。为什么我的实现不起作用?这是为了布局,要使视图垂直或水平,您应该使用LinearLayout,或者您可以使用下面的RelativeLayout设置layout_等。在您的情况下,LinearLayout可能不适用于AppBarLayout和DrawerLayout。请接受答案,谢谢!有道理。我一定忘了基本的东西。我的错!谢谢你的回答。我用Relativelayout解决了这个问题。在我看来,LinearLayout
在这种情况下更简单,但我很高兴你已经解决了这个问题。然后,我必须删除android:layout\u marginTop=“?attr/actionBarSize”
。我还需要添加其他组件。所以,我需要相对的布局外面。
<?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>