3

In my android application I have Toolbar with SlidingLayer which that is simple library and extends from FrameLayout to make sliding on application. now when I try to use toolbar with this view I have to make it into FrameLayout, with this action scrolling my toolbar is not working.

I moved app:layout_scrollFlags="scroll|enterAlways" from <android.support.v7.widget.Toolbar to FrameLayout but scrolling it doesn't work again. for example my view with toolbar is:

enter image description here

Now how can I use app:layout_scrollFlags="scroll|enterAlways" and scrolling toolbar with this view?

My xml layout is:

<?xml version="1.0" encoding="utf-8"?>
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:slidingLayer="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    app:layout_scrollFlags="scroll|enterAlways">

    <com.test.sample.Core.Libraries.SlidingLayer.SlidingLayer
        android:id="@+id/sliderTabPages"
        android:layout_width="match_parent"
        android:layout_height="130dp"
        android:layout_marginLeft="8dp"
        android:layout_marginTop="56dp"
        android:layout_marginRight="8dp"
        android:elevation="5dp"
        app:offsetDistance="30dp"
        app:slidingEnabled="true"
        app:stickTo="top"
        slidingLayer:changeStateOnTap="true">

    </com.test.sample.Core.Libraries.SlidingLayer.SlidingLayer>

    <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="wrap_content"
            android:background="@android:color/white"
            app:contentInsetStartWithNavigation="0dp"
            app:popupTheme="@style/ThemeOverlay.AppCompat.Light"
            app:theme="@style/Toolbar.Light">

            <android.support.constraint.ConstraintLayout
                android:layout_width="match_parent"
                android:layout_height="match_parent">

            />

            </android.support.constraint.ConstraintLayout>
        </android.support.v7.widget.Toolbar>

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

</FrameLayout>
Viral Patel
  • 1,296
  • 1
  • 11
  • 24
DolDurma
  • 15,753
  • 51
  • 198
  • 377
  • you are missing scroll flags for your toolbar inside appbar. try setting flags and check. – karan Jan 09 '19 at 11:48
  • CollapsingToolbarLayout-hide/show toolbar on scrolling of layout=> https://stackoverflow.com/questions/49624963/how-to-implement-play-store-collapsing-toolbar-layout replace your SlidingLayer inplace of the Recycler view(@+id/list1"),set property as app:layout_behavior="@string/appbar_scrolling_view_behavior". Set app:layout_scrollFlags="scroll|enterAlways" to CollapsingToolbarLayout Dependency-> implementation 'com.android.support:design:28.0.0' – Pradip Tilala Jan 11 '19 at 05:08

1 Answers1

0

try this out:

<?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:slidingLayer="http://schemas.android.com/apk/res-auto">

    <android.support.design.widget.CoordinatorLayout
        android:layout_width="match_parent"
        android:layout_height="match_parent">

        <!--Can use any layout for your content important thing is app:layout_behavior="@string/appbar_scrolling_view_behavior"-->
        <FrameLayout
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            app:layout_behavior="@string/appbar_scrolling_view_behavior">

            <com.test.sample.Core.Libraries.SlidingLayer.SlidingLayer
                android:id="@+id/sliderTabPages"
                android:layout_width="match_parent"
                android:layout_height="130dp"
                android:layout_marginLeft="8dp"
                android:layout_marginTop="56dp"
                android:layout_marginRight="8dp"
                android:elevation="5dp"
                app:offsetDistance="30dp"
                app:slidingEnabled="true"
                app:stickTo="top"
                slidingLayer:changeStateOnTap="true" />

            <!--Other content-->
            <!--Note that this content has to have scrollable view like RecyclerView-->
            <!--Example-->
            <RecyclerView
                android:id="@+id/yoursScrollableView"
                android:layout_width="match_parent"
                android:layout_height="match_parent" />

        </FrameLayout>

        <com.google.android.material.appbar.AppBarLayout
            android:layout_width="match_parent"
            android:layout_height="wrap_content">

            <!--Collapsing toolbar-->
            <!--You can put any kind of view for scrolling important thing is app:layout_scrollFlags="scroll|enterAlways"-->
            <android.support.v7.widget.Toolbar
                android:id="@+id/toolbarThatGoingToScroll"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:background="@android:color/white"
                app:contentInsetStartWithNavigation="0dp"
                app:layout_scrollFlags="scroll|enterAlways"
                app:popupTheme="@style/ThemeOverlay.AppCompat.Light"
                app:theme="@style/Toolbar.Light" />

        </com.google.android.material.appbar.AppBarLayout>
    </android.support.design.widget.CoordinatorLayout>
</layout>
Antonis Radz
  • 3,036
  • 1
  • 16
  • 34
  • While this code may solve the question, [including an explanation](https://meta.stackexchange.com/questions/114762/explaining-entirely-code-based-answers) of how and why this solves the problem would really help to improve the quality of your post, and probably result in more up-votes. Remember that you are answering the question for readers in the future, not just the person asking now. Please [edit] your answer to add explanation, and give an indication of what limitations and assumptions apply. – double-beep Mar 01 '19 at 14:55