Shadab Mehdi
Shadab Mehdi

Reputation: 653

Fragment contents are overlapping on ActionBar in Navigation Drawer

Why is the Fragment Layout overlapping the ActionBar like this

  1. FirstFragment

    <FrameLayout 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=".FirstFragment">
    
    <!-- TODO: Update blank fragment layout -->
    <TextView
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:text="@string/hello_first_fragment" />
    

    enter image description here

  2. SecondFragment

    <!-- TODO: Update blank fragment layout -->
    <TextView
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:text="@string/hello_second_fragment" />
    

    enter image description here

activity_navigation

<?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_navigation"
        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_navigation"
        app:menu="@menu/activity_navigation_drawer" />

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

app_bar_navigation

<?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.sup.slideup.Navigation">

    <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="?attr/colorPrimary"
            app:popupTheme="@style/AppTheme.PopupOverlay" />

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

    <FrameLayout
        android:id="@+id/main_fragment_holder"
        android:layout_width="match_parent"
        android:layout_height="match_parent"></FrameLayout>

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

Using KitKat Device.

Upvotes: 2

Views: 4193

Answers (1)

asadmshah
asadmshah

Reputation: 1368

If you want to maintain the non-LinearLayout in your Activity layout you need to set a layout_marginTop on the FrameLayout that holds your Fragment. In your app_bar_navigation.xml:

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

<FrameLayout
    android:id="@+id/main_fragment_holder"
    android:layout_width="match_parent"
    android:layout_height="match_parent" 
    android:layout_marginTop="?attr/actionBarSize"
    />
...

Upvotes: 8

Related Questions