【问题标题】:Me recycler view comes on top of the navigation drawer我的回收站视图位于导航抽屉的顶部
【发布时间】: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 之后。您还应该将&lt;include&gt;RecyclerView 放在另一个ViewGroup 中,因为您实际上应该只有一个内容View
  • 放入另一个 ViewGroup 是什么意思?我是安卓新手。请告诉。
  • 我的意思是,把它们放在里面,例如,一个垂直的&lt;LinearLayout&gt;This post 有一个正确的 DrawerLayout 设置示例。在接受的答案中,您的&lt;include&gt; 位于&lt;Toolbar&gt; 所在的位置,&lt;RecyclerView&gt; 紧随其后,您的&lt;NavigationView&gt; 代替最后一个&lt;LinearLayout&gt;,在底部。
  • 先生,我得到了解决方案,我有一个名为 content_main.xml 的单独 xml,它有一个相对布局。我只是把我的回收站视图放在里面,它就起作用了。非常感谢先生。

标签: android android-recyclerview navigation-drawer drawerlayout


【解决方案1】:

这是我的工作版本:您需要 DrawerLayout 中的其他布局(例如这里的 RelativeLayout)。然后你应该包括你的 AppBar

<?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"
    layout_height="wrap_content"
    layout_width="wrap_content"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:fitsSystemWindows="true">

    <RelativeLayout
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:orientation="vertical"
        tools:context="com.example.blablabla.MainActivity">

        <include
            android:id="@+id/app_bar"
            layout="@layout/app_bar"></include>

        <android.support.v7.widget.RecyclerView
            android:id="@+id/newsList"
            android:layout_below="@+id/app_bar"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_gravity="center_horizontal">

        </android.support.v7.widget.RecyclerView>
    </RelativeLayout>


    <fragment
        android:id="@+id/fragment_navigation_drawer"
        android:name="com.example.blabla.NavigationDrawerFragment"
        android:layout_width="@dimen/nav_drawer_width"
        android:layout_height="match_parent"
        android:layout_gravity="start"
        app:layout="@layout/fragment_navigation_drawer"
        tools:layout="@layout/fragment_navigation_drawer"></fragment>
</android.support.v4.widget.DrawerLayout>

这是我的导航片段:在此示例中,NavigationDrawer 在顶部有一个 ImageView,每个列表都有一个 Img 和文本。

<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"
    tools:context="com.example.blabla.NavigationDrawerFragment"
    android:orientation="vertical">

    <LinearLayout
        android:id="@+id/linid"
        android:layout_width="match_parent"
        android:layout_height="120dp"
        android:background="#0064a7"
        android:paddingLeft="20dp">

        <ImageView
            android:layout_width="240dp"
            android:layout_height="120dp"
            android:elevation="20dp"
            android:gravity="center_vertical"
            android:src="@drawable/zanderlogo" />
    </LinearLayout>

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

    </android.support.v7.widget.RecyclerView>    
</LinearLayout>

【讨论】:

  • 导航视图应该放在哪里?
  • 我认为您的 navigationView 是我的导航抽屉。我为此使用了一个片段。
  • 我编辑了我的答案并添加了我的导航抽屉的片段。看看和玩吧:)
  • 先生,我已经用其他 xml 编辑了我的问题,请告诉我要更改的内容。
  • 先生,我得到了解决方案,我有一个名为 content_main.xml 的单独 xml,它有一个相对布局。我只是把我的回收站视图放在里面,它就起作用了。非常感谢先生。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2014-06-11
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多