2

I've tried to clone the Google Playstore UI. So, I've a NavigationView, CoordinatorLayout -> AppBarLayout -> Toolbar, TabLayout, ViewPager. A tab has a layout where there are n horizontal RecyclerViews within 1 vertical RecyclerView.

My questions:

  1. Toolbar gets hidden on scrolling up iff the areas of the vertical list where the horizontal list items aren't visible (the gray background in the screenshot attached) are touched to scroll. If I am scrolling up by touching the inner list the scrolling takes place but the toolbar doesn't hide.

enter image description here

  1. How do I hide the tab header as well on scroll up.

My layout files:

activity_navigation_drawer.xml: Main activity layout

<?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/layout_main_content_nav_drawer"
        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/header_navigation_drawer"
        app:menu="@menu/menu_navigation_drawer"/>

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

layout_main_content_nav_drawer.xml: included in the above layout

<?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.aishwarya.materialdesign1.NavigationDrawerActivity">

    <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"
            app:layout_scrollFlags="scroll|enterAlways"/>

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

    <include layout="@layout/layout_content_nav_drawer"/>

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

layout_content_nav_drawer.xml: included in the above layout

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout
    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/content_navigation_drawer"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    app:layout_behavior="@string/appbar_scrolling_view_behavior"
    tools:context="com.aishwarya.materialdesign1.NavigationDrawerActivity"
    tools:showIn="@layout/layout_main_content_nav_drawer">

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

fragment_home_screen.xml: fragment that contains the TabLayout & ViewPager. I open this from my main activity to display the content.

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout 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:orientation="vertical">

    <android.support.design.widget.TabLayout
        android:id="@+id/tl_sliding"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        app:tabMode="fixed"
        app:tabSelectedTextColor="@color/color_primary"
        app:tabTextColor="@android:color/black"
        app:tabIndicatorColor="@color/color_primary"
        app:tabIndicatorHeight="2dp"/>

    <android.support.v4.view.ViewPager
        android:id="@+id/view_pager"
        android:layout_width="match_parent"
        android:layout_height="0px"
        android:layout_weight="1"
        android:background="@android:color/white"
        app:layout_behavior="@string/appbar_scrolling_view_behavior"/>

</LinearLayout>
Suraj Makhija
  • 1,376
  • 8
  • 16
Aishwarya Tiwari
  • 625
  • 4
  • 19

0 Answers0