Sriram
Sriram

Reputation: 449

Part of Fragment items hides under Action bar

I am learning android dev and my question might be very simple. I am stuck at the below part and requesting your help

Description

I am using the android's default "Navigation Drawer" activity to implement a small project. I have created a fragment and when user selects an option from Navigation drawer, the fragment opens.

Problem faced

When the fragment opens, part of the fragment & action bar is clipped. Image belowenter image description here

Code

fragment layout

<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"
android:fitsSystemWindows="true"
android:clipToPadding="false"
android:orientation="vertical"
android:background="#ffffff"
android:layout_weight="120"
tools:context="test.navigationdrawcheck.RateCalculator">

  <EditText
    android:layout_width="wrap_content"
    android:layout_height="5dp"
    android:inputType="number"
    android:ems="12"
    android:gravity="center"
    android:layout_weight="10"
    android:hint="text 1"
    android:textColorHint="@color/colorDivider"
    android:id="@+id/editText"
    android:layout_gravity="center_horizontal" />

<EditText
    android:layout_width="wrap_content"
    android:layout_height="5dp"
    android:inputType="number"
    android:hint="text 2"
    android:textColorHint="@color/colorDivider"
    android:ems="12"
    android:gravity="center"
    android:layout_weight="10"
    android:id="@+id/editText1"
    android:layout_gravity="center_horizontal" />

<EditText
    android:layout_width="wrap_content"
    android:layout_height="5dp"
    android:inputType="number"
    android:hint="text 3"
    android:textColorHint="@color/colorDivider"
    android:ems="12"
    android:gravity="center"
    android:layout_weight="10"
    android:id="@+id/editText3"
    android:layout_gravity="center_horizontal" />

<EditText
    android:layout_width="wrap_content"
    android:layout_height="5dp"
    android:inputType="number"
    android:hint="text 4"
    android:textColorHint="@color/colorDivider"
    android:ems="12"
    android:gravity="center"
    android:layout_weight="10"
    android:id="@+id/editText4"
    android:layout_gravity="center_horizontal" />

<TextView
    android:layout_width="wrap_content"
    android:layout_height="15dp"
    android:textAppearance="?android:attr/textAppearanceMedium"
    android:text="Total "
    android:textColor="@color/colorDivider"
    android:layout_weight="10"
    android:textStyle="bold"
    android:gravity="center_vertical"
    android:id="@+id/textView"
    android:layout_gravity="center_horizontal"
    />

<Button
    android:layout_width="match_parent"
    android:layout_height="10dp"
    android:inputType="number"
    android:ems="15"
    android:gravity="center"
    android:layout_weight="5"
    android:id="@+id/editText6"
    android:text="Submit"
    android:textSize="20sp"
    android:textColor="@color/colorWhite"
    android:background="@color/colorPrimary"
    android:layout_gravity="center_horizontal" />

App Bar Code

<?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="test.navigationdrawcheck.MainActivity">

    <android.support.design.widget.AppBarLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:fitsSystemWindows="true"
        android:theme="@style/AppTheme.AppBarOverlay">


        <android.support.v7.widget.Toolbar
            android:id="@+id/toolbar"
            android:elevation="4dp"
            android:layout_width="match_parent"
            android:layout_height="?attr/actionBarSize"
            android:background="?attr/colorPrimary"
            android:fitsSystemWindows="true"
            app:popupTheme="@style/AppTheme.PopupOverlay"/>

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

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

    </FrameLayout>

    <android.support.design.widget.FloatingActionButton
        android:id="@+id/fab"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_gravity="bottom|end"
        android:layout_margin="@dimen/fab_margin"
        android:src="@android:drawable/ic_dialog_email" />

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

Actual output i am looking for

Below is my actual fragment layout xml. When i merge it with Navigation drawer it should not be clipped and fragment items should be displayed correctly

enter image description here

What I have tried so far

I tried adding this android:windowActionBarOverlay=false in my styles.xml but no luck

Requesting your suggestions

Upvotes: 14

Views: 8118

Answers (2)

Arash.Zandi
Arash.Zandi

Reputation: 1627

use FrameLayout instead of LinearLayout and add this to your FrameLayout of the fragment

android:layout_marginTop="?attr/actionBarSize"

at leaset worked for me.

Upvotes: 12

NSimon
NSimon

Reputation: 5287

This might come from the default behaviour of the CoordinatorLayout. I also assume that you add your fragments in the frameLayout frameCheck. In your app bar code layout, replace

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

with :

<FrameLayout
    android:id="@+id/framecheck"
    app:layout_behavior="android.support.design.widget.AppBarLayout$ScrollingViewBehavior"
    android:layout_width="match_parent"
    android:layout_height="match_parent" />

Upvotes: 30

Related Questions