5

I have HomeActivity which contains fragment and at the bottom it has custom navigation view as shown below.

enter image description here

By clicking on profile pic, it replaces the fragment with UserProfileView fragment. userProfileView fragment has Collapsing toolbar inside coordinatorLayout.

userprofileview.xml

<?xml version="1.0" encoding="utf-8"?>
<layout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:bind="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools">

    <data>

        <variable
            name="resource"
            type="com.example.app.model.ResourceData" />


        <import type="android.view.View" />

    </data>

    <android.support.design.widget.CoordinatorLayout
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:background="@color/bg_home"
        android:fitsSystemWindows="true">

        <android.support.design.widget.AppBarLayout
            android:id="@+id/app_bar"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:background="@color/bg_home">

            <android.support.design.widget.CollapsingToolbarLayout
                android:id="@+id/toolbar_layout"
                android:layout_width="match_parent"
                android:layout_height="match_parent"
                app:layout_scrollFlags="scroll|exitUntilCollapsed">

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


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

        <LinearLayout
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:orientation="vertical"
            app:layout_behavior="@string/appbar_scrolling_view_behavior">

            <LinearLayout
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:layout_marginTop="@dimen/_10sdp"
                android:orientation="horizontal">

                <ImageView
                    android:id="@+id/ic_list"
                    android:layout_width="@dimen/_17sdp"
                    android:layout_height="@dimen/_17sdp"
                    android:layout_gravity="center"
                    android:layout_marginLeft="@dimen/_10sdp"
                    android:background="@drawable/ic_list_selected" />

                <ImageView
                    android:id="@+id/ic_grid_view"
                    android:layout_width="@dimen/_15sdp"
                    android:layout_height="@dimen/_15sdp"
                    android:layout_gravity="center"
                    android:layout_marginLeft="@dimen/_10sdp"
                    android:background="@drawable/ic_grid_unselected" />
            </LinearLayout>

            <android.support.v7.widget.RecyclerView
                android:visibility="gone"
                android:id="@+id/rv_post"
                android:layout_width="match_parent"
                android:layout_height="match_parent"
                app:resource="@{resource}" />

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

The problem is when i click to any other menu from bottom navigation menu, it scrolls off the screen as shown below.

enter image description here

This issue is occurring after adding CoordinatorLayout in UserProfileView framgment.

If i replace CoordinatorLayout with LinearLayout then it works fine but doesn't get the functionality of collapsing toolbar.

Thank you!

chetan
  • 681
  • 4
  • 21
  • I think the scenario you are describing here is similar to [the issue here](https://stackoverflow.com/questions/30777698/android-footer-scrolls-off-screen-when-used-in-coordinatorlayout) so I suggest trying to implement one of the recent solutions there – Noa Drach Nov 12 '17 at 15:59
  • @NoaDrach I've tried that and also commented my question over there. Thank you. – chetan Nov 13 '17 at 09:55
  • Can you post a simple project with that behavior at github? – azizbekian Nov 13 '17 at 16:45
  • Yeah sure. https://github.com/chetanparmar95/TestApp. Also I've used "Theme.AppCompat.Light.NoActionBar" theme but if I use DarkActionBar instead of NoActionBar then it works properly but ActionBar comes down the same way BottomView is moving – chetan Nov 14 '17 at 06:48

1 Answers1

1

android:fitsSystemWindows="true" in your fragment_user_profile.xml causes problem. Simply... it makes your drawer layout looks fullscreen.

Roughly, user screen maintains top indicator margin and home screen doesn't. So home screen moved up as indicator size. (Actually it isn't, Details about fitsSystemWindows: Why would I want to fitsSystemWindows)

So, remove fitsSystemWindows from fragment_user_profile.xml will fix your problem.

And I suggest you add fitsSystemWindows to your container_body in activity_main.xml, but I'm not sure that what is the actual code, so it is your call.

Stanley Ko
  • 3,383
  • 3
  • 34
  • 60