NavigationView перекрывает содержимое

У меня есть приложение, в которое я пытаюсь добавить NavigationView. Я сделал это:

main_activity.xml:

<?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="match_parent" />

<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>

app_bar_main.xml:

<?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"
android:fitsSystemWindows="true"
tools:context="com.example.testnavigation2.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="@android:color/holo_red_dark"
        app:popupTheme="@style/AppTheme.PopupOverlay" />

</android.support.design.widget.AppBarLayout>

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

</android.support.design.widget.CoordinatorLayout>

content_profiles.xml:

<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"
android:background="@drawable/register_background"
android:layout_gravity="center" >

<TextView
    android:id="@+id/text_NoProfile"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:visibility="visible"
    android:layout_centerHorizontal="true"
    android:text="No items in profiles database." />

<ListView
    android:id="@+id/listView_users"
    android:layout_below="@id/text_NoProfile"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:visibility="gone"
    android:layout_centerHorizontal="true"
    android:background="@color/gray_back" />

<Button
    android:id="@+id/buttonAddProfile"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:padding="10dp"
    android:layout_marginTop="5dp"
    android:layout_centerHorizontal="true"
    android:background="@drawable/button_style"
    android:text="Add profile"
    android:layout_below="@id/listView_users"
    android:textColor="#ffffff" />

<ImageView
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_alignParentBottom="true"
    android:layout_centerHorizontal="true"
    android:src="@drawable/pull_down_button" />

</RelativeLayout>

А это мой nav_header_main.xml:

<?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:gravity="bottom"
android:orientation="vertical"
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">

<ImageView
    android:id="@+id/imageView"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:paddingTop="@dimen/nav_header_vertical_spacing"
    android:src="@android:drawable/sym_def_app_icon" />

<TextView
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:paddingTop="@dimen/nav_header_vertical_spacing"
    android:text="Android Studio"
    android:textAppearance="@style/TextAppearance.AppCompat.Body1" />

<TextView
    android:id="@+id/textView"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:text="[email protected]" />

</LinearLayout>

Когда я загружаю свое приложение, оно выглядит так:

введите здесь описание изображения

Как видите, моя кнопка обрезана nav_header, но я понятия не имею, почему.

Может ли кто-нибудь помочь мне с этим? ИЗМЕНИТЬ:

Когда я добавляю модификации, предложенные @Abhilash, теперь это выглядит так:

введите здесь описание изображения

И все перемещается вниз по этому пространству. Что я делаю неправильно?

ПРИМЕЧАНИЕ: все мои стили ПОЛНОЭКРАННЫЕ! Не знаю, интересно узнать...


person Sonhja    schedule 23.11.2015    source источник
comment
можете ли вы поместить свой макет панели приложений и макет ‹include› в RelativeLayout в app_bar_main.xml   -  person Bhargav Thanki    schedule 23.11.2015


Ответы (1)


Добавьте поведение прокрутки в относительный макет вашего контента.

Ex:

app:layout_behavior="@string/appbar_scrolling_view_behavior"

XML:

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:layout_gravity="center"
    android:background="@drawable/register_background"
    app:layout_behavior="@string/appbar_scrolling_view_behavior">

    <TextView
        android:id="@+id/text_NoProfile"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_centerHorizontal="true"
        android:text="No items in profiles database."
        android:visibility="visible" />

    <ListView
        android:id="@+id/listView_users"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:layout_below="@id/text_NoProfile"
        android:layout_centerHorizontal="true"
        android:background="@color/gray_back"
        android:visibility="gone" />

    <Button
        android:id="@+id/buttonAddProfile"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_below="@id/listView_users"
        android:layout_centerHorizontal="true"
        android:layout_marginTop="5dp"
        android:background="@drawable/button_style"
        android:padding="10dp"
        android:text="Add profile"
        android:textColor="#ffffff" />

    <ImageView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentBottom="true"
        android:layout_centerHorizontal="true"
        android:src="@drawable/pull_down_button" />

</RelativeLayout>
person arbrcr    schedule 23.11.2015
comment
Частично работает... Теперь все так сильно смещается вниз... (ПРИМЕЧАНИЕ: у меня приложение в полноэкранном режиме). Посмотрите мое редактирование, чтобы увидеть, как это выглядит сейчас! - person Sonhja; 23.11.2015
comment
Любая идея о том, почему мой экран выглядит более вниз, чем ожидалось? - person Sonhja; 23.11.2015
comment
попробуйте удалить android:layout_gravity=center из вашего относительного макета - person arbrcr; 23.11.2015