【发布时间】:2016-08-26 05:56:52
【问题描述】:
我的回收站视图与我的导航抽屉重叠。以下是我的布局代码-
<?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"
android:orientation="vertical"
tools:context="com.theappsolutes.shaadi.activities.HomeScreen">
<include layout="@layout/app_bar_main" android:layout_width="match_parent"
android:layout_height="match_parent" />
<android.support.v7.widget.RecyclerView
android:id="@+id/card_recycler_view"
android:scrollbars="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent"/>
</RelativeLayout>
<android.support.design.widget.NavigationView android:id="@+id/nav_view"
android:layout_width="wrap_content" android:layout_height="match_parent"
android:layout_gravity="start" android:fitsSystemWindows="true"
app:headerLayout="@layout/nav_header_main" app:menu="@menu/activity_main_drawer" />
</android.support.v4.widget.DrawerLayout>
我想将回收器视图放置在顶部导航抽屉的活动中。请帮忙。
我的导航标题是这样的 -
<?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="@dimen/nav_header_height"
android:background="@drawable/side_nav_bar"
android:paddingBottom="@dimen/activity_vertical_margin"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
android:theme="@style/ThemeOverlay.AppCompat.Dark" android:orientation="vertical"
android:gravity="bottom">
<TextView android:id="@+id/user_full_name" android:layout_width="match_parent" android:layout_height="wrap_content"
android:paddingTop="@dimen/nav_header_vertical_spacing"
android:textAppearance="@style/TextAppearance.AppCompat.Body1" />
<TextView android:layout_width="wrap_content" android:layout_height="wrap_content"
android:id="@+id/user_email_id" />
</LinearLayout>
我的主抽屉就像-
<?xml version="1.0" encoding="utf-8"?>
<menu xmlns:android="http://schemas.android.com/apk/res/android">
<group android:checkableBehavior="single">
<item android:id="@+id/nav_logout" android:icon="@drawable/ic_power_settings_new_black_36dp"
android:title="@string/logout" />
</group>
</menu>
【问题讨论】:
-
您的抽屉需要在
DrawerLayout中最后列出。也就是说,将NavigationView移动到RecyclerView之后。您还应该将<include>和RecyclerView放在另一个ViewGroup中,因为您实际上应该只有一个内容View。 -
放入另一个 ViewGroup 是什么意思?我是安卓新手。请告诉。
-
我的意思是,把它们放在里面,例如,一个垂直的
<LinearLayout>。 This post 有一个正确的DrawerLayout设置示例。在接受的答案中,您的<include>位于<Toolbar>所在的位置,<RecyclerView>紧随其后,您的<NavigationView>代替最后一个<LinearLayout>,在底部。 -
先生,我得到了解决方案,我有一个名为 content_main.xml 的单独 xml,它有一个相对布局。我只是把我的回收站视图放在里面,它就起作用了。非常感谢先生。
标签: android android-recyclerview navigation-drawer drawerlayout