0

In my android application I have to show one linear layout and a RecyclerView below the linear layout, when the user reaches the bottom of the RecyclerView by scrolling I have to hide the LinearLayout with a parallax effect. I am not prefer to use any third party libraries and dependencies. I have to use android design library only. I think, using coordinate layout can do this.

xml

<LinearLayout 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:orientation="vertical"
    android:paddingBottom="@dimen/dimen_sm"
    android:paddingLeft="@dimen/dimen_sm"
    android:paddingRight="@dimen/dimen_sm"
    android:paddingTop="@dimen/dimen_sm"
    tools:context=".MainActivity">

            <LinearLayout
                android:id="@+id/top_view"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:background="@color/white"
                android:orientation="vertical"
                android:paddingBottom="@dimen/dimen_sm"
                android:paddingTop="@dimen/dimen_sm"
                app:layout_collapseMode="parallax">

                <EditText
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content" />

            </LinearLayout>

 <android.support.v7.widget.RecyclerView
            app:layout_scrollFlags="pin"
            android:id="@+id/recycler_list"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:layout_marginTop="@dimen/dimen_xs"/>

</LinearLayout>

can any one help me to do this ?

UPDATE

<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"
    android:paddingBottom="@dimen/dimen_sm"
    android:paddingLeft="@dimen/dimen_sm"
    android:paddingRight="@dimen/dimen_sm"
    android:paddingTop="@dimen/dimen_sm"
    tools:context=".MainActivity">

    <android.support.design.widget.AppBarLayout
        android:layout_width="match_parent"
        android:layout_height="100dp"
        android:fitsSystemWindows="true">

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


            <LinearLayout
                android:id="@+id/top_view"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:background="@color/white"
                android:orientation="vertical"
                android:paddingBottom="@dimen/dimen_sm"
                android:paddingTop="@dimen/dimen_sm"
                app:layout_collapseMode="parallax">

                <EditText
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content" />
            </LinearLayout>

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

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

    <android.support.v4.widget.NestedScrollView
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        app:layout_behavior="@string/appbar_scrolling_view_behavior">

        <android.support.v7.widget.RecyclerView
            android:id="@+id/recycler_list"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:layout_marginTop="@dimen/dimen_xs" />
    </android.support.v4.widget.NestedScrollView>
    `

    <!--<android.support.v7.widget.RecyclerView

        app:layout_collapseMode="pin"
        android:id="@+id/recycler_list"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
                android:layout_marginTop="@dimen/dimen_xs"
        android:background="@color/white" />-->
</android.support.design.widget.CoordinatorLayout>

I have changed my code to this. now the paralax is working, but the recyclerView is not coming

Cœur
  • 37,241
  • 25
  • 195
  • 267
droidev
  • 7,352
  • 11
  • 62
  • 94

2 Answers2

0

Try this.

<android.support.design.widget.CoordinatorLayout
android:id="@+id/product_detail_main_content"
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:apptools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent">

<android.support.design.widget.AppBarLayout
    android:id="@+id/appbar"
    android:layout_width="match_parent"
    android:layout_height="@dimen/product_detail_app_bar_height"
    android:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar">

    <android.support.design.widget.CollapsingToolbarLayout
        android:id="@+id/detail_product_collapsing_toolbar"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:clipToPadding="true"
        android:foregroundGravity="bottom|right"
        android:foregroundTintMode="add"
        app:contentScrim="?attr/colorPrimary"
        app:expandedTitleMarginStart="@dimen/space_xxlarge"
        app:layout_scrollFlags="scroll|exitUntilCollapsed">

        <FrameLayout
            android:layout_width="match_parent"
            android:layout_height="match_parent">

            <ImageView
                android:id="@+id/detail_image_head"
                android:layout_width="match_parent"
                android:layout_height="match_parent"
                android:scaleType="centerCrop"
                android:fitsSystemWindows="true"
                app:layout_collapseMode="parallax"
                app:layout_collapseParallaxMultiplier="0.7"/>

                <View
                    android:layout_width="match_parent"
                    android:layout_height="match_parent"
                    android:background="@drawable/gradient_shape" />
        </FrameLayout>

        <android.support.v7.widget.Toolbar
            android:id="@+id/product_toolBar_title"
            android:layout_width="match_parent"
            android:layout_height="?attr/actionBarSize"
            android:fitsSystemWindows="true"
            app:layout_collapseMode="pin"
            app:navigationIcon="@drawable/ic_arrow_back_white_24dp"
            app:popupTheme="@style/ThemeOverlay.AppCompat.Light"
            app:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar"/>

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

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

<android.support.v4.widget.NestedScrollView
    android:id="@+id/detail_product_scrollView"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    app:layout_behavior="@string/appbar_scrolling_view_behavior">

<android.support.v7.widget.RecyclerView
            android:id="@+id/product_recycler_Thumbnail"
            android:layout_width="match_parent"
            android:layout_height="78dp"
            android:clipToPadding="false"
            android:scrollbars="vertical"
            android:elevation="@dimen/space_low"/>
........
</android.support.v4.widget.NestedScrollView>

</android.support.design.widget.CoordinatorLayout>
Abhishek
  • 2,350
  • 2
  • 21
  • 35
0

I think you want this, try it :

<android.support.design.widget.CoordinatorLayout
    android:id="@+id/clMain"
    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.support.v7.widget.RecyclerView
        android:id="@+id/rvMoviesUpdate"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        app:layout_behavior="@string/appbar_scrolling_view_behavior" />

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

        <android.support.v7.widget.Toolbar
            android:id="@+id/toolbar"
            app:layout_scrollFlags="scroll|enterAlways"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:background="@color/colorPrimary" />
        <LinearLayout
            android:id="@+id/top_view"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:background="@color/white"
            android:orientation="vertical"
            android:paddingBottom="@dimen/dimen_sm"
            android:paddingTop="@dimen/dimen_sm"
            app:layout_scrollFlags="scroll|enterAlways">

            <EditText
                android:layout_width="match_parent"
                android:layout_height="wrap_content" />
        </LinearLayout>
    </android.support.design.widget.AppBarLayout>
</android.support.design.widget.CoordinatorLayout>

With scroll effect on EditText and Toolbar.

SANAT
  • 8,489
  • 55
  • 66