I have a code here which contains of a coordinator layout. Inside that coordinator layout, there is an appbar layout and a nested scrollview beneath it.I want the appbar layout(map) to be still even when nestedscroll view scrolls.I have images to explain my thoughts. Initial stage, stage two. Notice that the map remains still while only nested scroll view scrolls and finally, nested scroll view overlaps entire map fragment.
<?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:id="@+id/main_content"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fitsSystemWindows="true"
android:background="@android:color/white">
<android.support.design.widget.AppBarLayout
android:id="@+id/MyAppbar"
android:layout_width="match_parent"
android:layout_height="550dp"
android:fitsSystemWindows="true"
>
<android.support.design.widget.CollapsingToolbarLayout
android:id="@+id/collapse_toolbar"
android:layout_width="match_parent"
android:layout_height="match_parent"
app:layout_scrollFlags="scroll|exitUntilCollapsed"
android:fitsSystemWindows="true">
<android.support.v7.widget.Toolbar
android:id="@+id/my_toolbar"
android:layout_width="match_parent"
android:layout_height="60dp"
app:layout_collapseMode="pin"
>
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent">
<ImageView
android:id="@+id/close_button"
android:layout_width="35dp"
android:layout_height="35dp"
android:layout_centerVertical="true"
android:src="@drawable/close_black"
/>
<TextView
android:id="@+id/shipping_to_title"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="SHIPPING TO"
android:textColor="@color/black"
android:textStyle="bold"
android:textSize="10dp"
android:layout_centerHorizontal="true"
android:layout_marginTop="10dp"/>
<TextView
android:id="@+id/shipping_to"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="926 Rosenbaum Mill"
android:textColor="@color/black"
android:layout_below="@id/shipping_to_title"
android:textSize="16dp"
android:layout_centerHorizontal="true"/>
</RelativeLayout>
</android.support.v7.widget.Toolbar>
<fragment
android:id="@+id/map"
android:name="com.google.android.gms.maps.SupportMapFragment"
android:layout_width="match_parent"
android:layout_height="550dp"
tools:context=".MapFragment"
android:layout_below="@id/my_toolbar"
app:layout_collapseMode="pin"
>
<RelativeLayout
android:id="@+id/outermost_wrapper"
android:layout_width="match_parent"
android:layout_height="match_parent"
>
<RelativeLayout
android:id="@+id/bottom_wrapper"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_marginBottom="20dp"
android:layout_marginStart="20dp"
android:layout_marginEnd="20dp"
android:layout_centerHorizontal="true"
>
<include
android:id="@+id/getDirections"
layout="@layout/track_shipment_activity_get_directions_fragment_layout"
android:visibility="gone"
android:layout_height="wrap_content"
android:layout_width="wrap_content"
android:layout_centerHorizontal="true"
/>
<include
android:id="@+id/received"
layout="@layout/track_shipment_activity_received_fragment_layout"
android:visibility="gone"
android:layout_height="wrap_content"
android:layout_width="wrap_content"
android:layout_centerHorizontal="true"
/>
<include
android:id="@+id/enrouteToDestination"
layout="@layout/track_shipment_activity_button_fragment_layout"
android:visibility="gone"
android:layout_height="wrap_content"
android:layout_width="wrap_content"
android:layout_centerHorizontal="true"
/>
<include
android:id="@+id/trackOrder"
layout="@layout/track_shipment_track_order_button_fragment_layout"
android:visibility="gone"
/>
<RelativeLayout
android:id="@+id/trackOrderBelow"
android:layout_width="300dp"
android:layout_height="40dp"
android:layout_below="@id/trackOrder"
android:layout_marginBottom="20dp"
android:background="#FBFBFB"
android:layout_centerHorizontal="true"
android:visibility="gone">
<TextView
android:id="@+id/tracking_code_title"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/tracking_code"
android:textSize="14dp"
android:textColor="@color/black"
android:layout_marginStart="10dp"
android:layout_centerVertical="true"/>
<TextView
android:id="@+id/tracking_code"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/tracking_code_numbers"
android:layout_toRightOf="@id/tracking_code_title"
android:textSize="14dp"
android:textColor="@color/black"
android:layout_marginStart="10dp"
android:layout_centerVertical="true" />
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="@drawable/double_boxes"
android:layout_alignParentEnd="true"
android:layout_marginEnd="10dp"
android:layout_centerVertical="true"/>
</RelativeLayout>
</RelativeLayout>
</RelativeLayout>
</fragment>
</android.support.design.widget.CollapsingToolbarLayout>
</android.support.design.widget.AppBarLayout>
<android.support.v4.widget.NestedScrollView 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:layout_gravity="fill_vertical"
app:layout_behavior="@string/appbar_scrolling_view_behavior">
<RelativeLayout xmlns:app="http://schemas.android.com/apk/res-auto"
android:id="@+id/abc"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_below="@id/MyAppbar"
android:layout_marginTop="30dp"
tools:context=".MapFragment">
<RelativeLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content">
<ScrollView
android:id="@+id/scroll_view"
android:layout_width="match_parent"
android:layout_height="match_parent">
<RelativeLayout
android:id="@+id/relative_layout_wrapper"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="@color/activity_background">
<RelativeLayout
android:id="@+id/relative_layout_inner"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="@android:color/white"
android:focusedByDefault="true">
<ImageView
android:id="@+id/order_icon"
android:layout_width="30dp"
android:layout_height="30dp"
android:layout_marginStart="15dp"
android:layout_marginTop="25dp"
android:contentDescription="@string/app_name"
android:src="@drawable/orders" />
<TextView
android:id="@+id/order_date_title"
android:layout_width="wrap_content"
android:layout_height="30dp"
android:layout_marginTop="25dp"
android:layout_toEndOf="@id/order_icon"
android:gravity="center"
android:paddingLeft="5dp"
android:text="@string/order_date2"
android:textColor="@android:color/black" />
<TextView
android:id="@+id/order_date"
android:layout_width="wrap_content"
android:layout_height="30dp"
android:layout_alignParentEnd="true"
android:layout_marginEnd="15dp"
android:layout_marginTop="25dp"
android:layout_toEndOf="@id/order_date_title"
android:gravity="center|end"
android:paddingLeft="90dp"
android:text="@string/date5"
android:textColor="@android:color/black"
android:textStyle="bold" />
<ImageView
android:id="@+id/placeBy_icon"
android:layout_width="30dp"
android:layout_height="30dp"
android:layout_below="@id/order_icon"
android:layout_marginStart="15dp"
android:layout_marginTop="20dp"
android:contentDescription="@string/app_name"
android:src="@drawable/person" />
<TextView
android:id="@+id/placed_by_title"
android:layout_width="wrap_content"
android:layout_height="30dp"
android:layout_below="@id/order_date_title"
android:layout_marginTop="20dp"
android:layout_toEndOf="@id/placeBy_icon"
android:gravity="center"
android:paddingLeft="5dp"
android:text="@string/placed_by"
android:textColor="@android:color/black" />
<TextView
android:id="@+id/placed_by"
android:layout_width="wrap_content"
android:layout_height="30dp"
android:layout_alignParentEnd="true"
android:layout_below="@id/order_date_title"
android:layout_marginEnd="15dp"
android:layout_marginTop="20dp"
android:layout_toEndOf="@id/placed_by_title"
android:gravity="center|end"
android:paddingLeft="100dp"
android:text="@string/user_name"
android:textColor="@android:color/black"
android:textStyle="bold" />
<ImageView
android:id="@+id/delivery_icon"
android:layout_width="30dp"
android:layout_height="30dp"
android:layout_below="@id/placeBy_icon"
android:layout_marginStart="15dp"
android:layout_marginTop="20dp"
android:contentDescription="@string/app_name"
android:src="@drawable/delivery" />
<TextView
android:id="@+id/delivery_method_title"
android:layout_width="wrap_content"
android:layout_height="30dp"
android:layout_below="@id/placed_by_title"
android:layout_marginTop="20dp"
android:layout_toEndOf="@id/delivery_icon"
android:gravity="center"
android:paddingLeft="5dp"
android:text="@string/delivery_method"
android:textColor="@android:color/black" />
<TextView
android:id="@+id/delivery_method"
android:layout_width="wrap_content"
android:layout_height="30dp"
android:layout_alignParentEnd="true"
android:layout_below="@id/placed_by_title"
android:layout_marginEnd="15dp"
android:layout_marginTop="20dp"
android:layout_toEndOf="@id/delivery_method_title"
android:gravity="center|end"
android:text="@string/shipping"
android:textColor="@android:color/black"
android:textStyle="bold" />
<RelativeLayout
android:id="@+id/add_to_calander_button_shipment"
android:layout_width="340dp"
android:layout_height="40dp"
android:layout_below="@+id/delivery_icon"
android:layout_centerHorizontal="true"
android:layout_marginBottom="20dp"
android:layout_marginTop="20dp"
android:background="@drawable/add_to_calander">
<RelativeLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:layout_centerVertical="true">
<ImageView
android:id="@+id/addToCalIcon"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:contentDescription="@string/app_name"
android:src="@drawable/orders" />
<TextView
android:id="@+id/addToCalText"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="5dp"
android:layout_marginTop="2dp"
android:layout_toEndOf="@id/addToCalIcon"
android:text="@string/add_to_calander"
android:textSize="14dp" />
</RelativeLayout>
</RelativeLayout>
</RelativeLayout>
<View
android:id="@+id/threeItems"
android:layout_width="match_parent"
android:layout_height="50dp"
android:layout_below="@+id/relative_layout_inner"
android:layout_marginStart="10dp"
android:layout_marginTop="30dp"
android:background="@color/activity_background" />
<TextView
android:id="@+id/threeItemstext"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="@+id/relative_layout_inner"
android:layout_marginStart="10dp"
android:layout_marginTop="30dp"
android:text="@string/number_of_items"
android:textColor="@color/black"
android:textSize="16dp"
android:textStyle="bold" />
<android.support.v4.widget.NestedScrollView
android:id="@+id/nestedRecyclerView"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_below="@id/threeItems">
<android.support.v7.widget.RecyclerView
android:id="@+id/simpleRecyclerView"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@android:color/white"
android:nestedScrollingEnabled="false"
app:layout_behavior="@string/app_bar_scrolling_view_behavior">
</android.support.v7.widget.RecyclerView>
</android.support.v4.widget.NestedScrollView>
<include
android:id="@+id/delivery_details"
layout="@layout/track_shipment_delivery_details_fragment"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@id/nestedRecyclerView"
android:layout_marginBottom="5dp"
android:layout_marginEnd="10dp"
android:layout_marginStart="10dp"
android:layout_marginTop="10dp" />
<include
android:id="@+id/order"
layout="@layout/track_shipment_order_total_fragment"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@id/delivery_details"
android:layout_marginBottom="5dp"
android:layout_marginEnd="10dp"
android:layout_marginStart="10dp"
android:layout_marginTop="5dp" />
<include
android:id="@+id/need_help"
layout="@layout/track_shipment_need_help_fragment"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@id/order"
android:layout_marginBottom="10dp"
android:layout_marginEnd="10dp"
android:layout_marginStart="10dp"
android:layout_marginTop="5dp" />
</RelativeLayout>
</ScrollView>
</RelativeLayout>
</RelativeLayout>
</android.support.v4.widget.NestedScrollView>
</android.support.design.widget.CoordinatorLayout>
Try adding
app:behavior_overlapTop="0dp"
in your nested scroll view and also add some elevation to the nested scroll view.