Alexander Farber
Alexander Farber

Reputation: 23058

Combining DrawerLayout with CoordinatorLayout and FAB

For my question I have prepared a simple project at GitHub.

In an app with DrawerLayout I am trying to display a login page for social networks (Google+, Facebook, Twitter).

The login page should display the social network logo (or user photo - if logged in), then horizontal progress bar and a FloatingActionButton and finally some text at the bottom:

app screenshot

Unfortunately, I have some strange artefact in the ActionBar area - as you can see in the right side of the above screenshot.

Why does it happen please and how to fix this?

Here is my activity_main.xml with DrawerLayout and left drawer menu:

<android.support.v4.widget.DrawerLayout
    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">

    <LinearLayout
        android:orientation="vertical"
        android:layout_width="match_parent"
        android:layout_height="match_parent">

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

        <FrameLayout
            android:id="@+id/root"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:background="#FF0"/>

    </LinearLayout>

    <android.support.design.widget.NavigationView
        android:id="@+id/left_drawer"
        android:layout_height="match_parent"
        android:layout_width="wrap_content"
        android:layout_gravity="start"
        android:fitsSystemWindows="true"
        android:background="#FFF"
        app:itemIconTint="@color/drawer_item_text"
        app:itemTextColor="@color/drawer_item_text"
        app:headerLayout="@layout/header_left"
        app:menu="@menu/menu_main"/>

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

And here is my fragment_google.xml with CoordinatorLayout and FAB:

<android.support.design.widget.CoordinatorLayout
    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:fitsSystemWindows="true">

    <LinearLayout android:layout_width="match_parent"
                  android:layout_height="match_parent"
                  android:orientation="vertical">

    <ImageView
        android:id="@+id/photo"
        android:layout_width="match_parent"
        android:layout_height="0dp"
        android:layout_weight="0.4"
        android:src="@drawable/photo"
        android:scaleType="centerCrop"
        app:layout_collapseMode="parallax" />

    <CheckBox
        android:layout_width="wrap_content"
        android:layout_height="0dp"
        android:layout_weight="0.2"
        android:layout_gravity="center_horizontal"
        android:text="Main profile"
        />

    <TextView
        android:id="@+id/given"
        android:layout_width="wrap_content"
        android:layout_height="0dp"
        android:layout_weight="0.2"
        android:layout_gravity="center_horizontal"
        />

    <TextView
        android:id="@+id/place"
        android:layout_width="wrap_content"
        android:layout_height="0dp"
        android:layout_weight="0.2"
        android:layout_gravity="center_horizontal"
        />

    </LinearLayout>

    <ProgressBar
        android:id="@+id/progress"
        android:indeterminate="true"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        app:layout_anchor="@id/photo"
        app:layout_anchorGravity="bottom"
        style="?android:attr/progressBarStyleHorizontal"/>

    <android.support.design.widget.FloatingActionButton
        android:id="@+id/fab"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_margin="8dp"
        app:layout_anchor="@id/photo"
        app:layout_anchorGravity="bottom|right|end"
        android:src="@drawable/ic_account_plus_white_48dp"
        android:elevation="8dp"/>

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

Upvotes: 2

Views: 3269

Answers (1)

Alexander Farber
Alexander Farber

Reputation: 23058

Removing fitsSystemWindows="true" from fragment_google.xml has solved the problem:

app screenshot

Upvotes: 2

Related Questions