1

I am setting a toolbar animation with help of nested scroll view. but the setOnScrollChangeListener is not working properly.

here the issue is setOnScrollChangeListener is not working. scrolling is not detecting

please help me to solve this issue. I think the issue is with my xml design because I just used the code in my demo project and it works perfectly. but in here it is not working. the scrolling is not detected.

this is my xml file

<?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:id="@+id/main_content"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical">
    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="40dp"
        android:orientation="vertical"
        android:gravity="center"
        android:background="#ffff">
        <LinearLayout
            android:id="@+id/new_bar"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:orientation="vertical"
            android:gravity="center"
            >

            <TextView
                android:id="@+id/new_tool"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:text="header text"
                android:textSize="16dp"
                android:textColor="@color/app_gray"
                android:textStyle="bold"/>

        </LinearLayout>
    </LinearLayout>

    <android.support.design.widget.CoordinatorLayout
        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="50dp"
        android:background="#FFF"
        android:fitsSystemWindows="true"
        android:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar">
        <LinearLayout
            android:layout_width="match_parent"
            android:layout_height="50dp"
            android:orientation="vertical"
            app:layout_scrollFlags="scroll|enterAlways">
            <TextView
                android:id="@+id/colapseHead"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:text="header text"
                android:layout_marginLeft="10dp"
                android:layout_marginBottom="5dp"
                android:textSize="30dp"
                android:textColor="@color/app_gray"
                android:textStyle="bold"/>
        </LinearLayout>

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


        <android.support.v4.widget.NestedScrollView
            android:id="@+id/nested_content"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:fillViewport="true"
            android:clipToPadding="false"
            android:scrollbars="none"
            android:scrollingCache="true"
            app:layout_behavior="@string/appbar_scrolling_view_behavior"
            android:layout_marginBottom="50dp">

            <android.support.v4.view.ViewPager
                android:id="@+id/viewpager"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:visibility="visible"
                android:focusableInTouchMode="true"
                android:background="#fff"
                />


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

    <android.support.design.widget.CoordinatorLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:visibility="gone"
        android:layout_gravity="bottom">
        <RelativeLayout
            android:id="@+id/lay_tabs"
            android:layout_width="match_parent"
            android:layout_alignParentBottom="true"
            android:layout_height="50dp">
            <View
                android:layout_width="match_parent"
                android:layout_height="1dp"
                android:background="@color/app_graylight"/>

            <android.support.design.widget.TabLayout
                android:id="@+id/tabs"
                android:layout_width="match_parent"
                android:layout_height="50dp"
                android:layout_below="@+id/re_lay"
                android:layout_alignParentBottom="true"
                android:background="@color/white"
                app:tabIndicatorColor="@null"
                />


            <LinearLayout
                android:layout_width="match_parent"
                android:layout_height="50dp"
                android:orientation="horizontal"
                android:weightSum="5">

                <RelativeLayout
                    android:layout_width="0px"
                    android:layout_height="match_parent"
                    android:translationZ="5dp"
                    android:layout_weight="1"
                    android:layout_marginLeft="8dp"
                    android:layout_marginRight="3dp"

                    >
                    <RelativeLayout
                        android:id="@+id/lay1"
                        android:layout_width="match_parent"
                        android:layout_height="match_parent"
                        android:background="@color/app_white"
                        android:visibility="visible">
                        <ImageView
                            android:id="@+id/img1"
                            android:layout_width="30dp"
                            android:layout_height="30dp"
                            android:padding="5dp"
                            android:layout_centerHorizontal="true"
                            android:layout_marginTop="5dp"
                            android:src="@drawable/home_tab_icon"/>
                        <com.nocon.spark.manager.FontFitTextView
                            android:layout_width="match_parent"
                            android:layout_height="wrap_content"
                            android:gravity="center"
                            android:layout_marginTop="1dp"
                            android:textSize="60sp"
                            android:textColor="@color/bottomtextcolor"
                            android:layout_below="@+id/img1"
                            android:text="@string/tab_home"
                            android:layout_centerHorizontal="true"/>

                    </RelativeLayout>
                </RelativeLayout>
                <RelativeLayout
                    android:layout_width="0px"
                    android:layout_weight="1"
                    android:layout_height="match_parent"
                    android:translationZ="5dp"
                    android:layout_marginLeft="3dp"
                    android:layout_marginRight="8dp"

                    >
                    <RelativeLayout
                        android:id="@+id/lay2"
                        android:layout_width="match_parent"
                        android:layout_height="match_parent"
                        android:background="@color/app_white"
                        android:visibility="visible">
                        <ImageView
                            android:id="@+id/img2"
                            android:layout_width="30dp"
                            android:layout_height="30dp"
                            android:padding="5dp"
                            android:layout_centerHorizontal="true"
                            android:layout_marginTop="5dp"
                            android:src="@drawable/virtual_tab_icon"/>
                        <com.nocon.spark.manager.FontFitTextView
                            android:layout_width="match_parent"
                            android:layout_height="wrap_content"
                            android:gravity="center"
                            android:layout_marginTop="1dp"
                            android:textSize="60sp"
                            android:textColor="@color/bottomtextcolor"
                            android:layout_below="@+id/img2"
                            android:text="@string/more_appointments"
                            android:layout_centerHorizontal="true"/>
                    </RelativeLayout>
                </RelativeLayout>
                <RelativeLayout
                    android:layout_width="0px"
                    android:layout_height="match_parent"
                    android:translationZ="5dp"
                    android:layout_weight="1"
                    android:layout_marginLeft="8dp"
                    android:layout_marginRight="8dp"

                    >
                    <RelativeLayout
                        android:id="@+id/lay5"
                        android:layout_width="match_parent"
                        android:layout_height="match_parent"
                        android:background="@color/app_white"
                        android:visibility="visible">
                        <ImageView
                            android:id="@+id/img5"
                            android:layout_width="30dp"
                            android:layout_height="30dp"
                            android:padding="5dp"
                            android:layout_centerHorizontal="true"
                            android:layout_marginTop="5dp"
                            android:src="@drawable/message_icon"/>
                        <com.nocon.spark.manager.FontFitTextView
                            android:layout_width="match_parent"
                            android:layout_height="wrap_content"
                            android:gravity="center"
                            android:layout_marginTop="1dp"
                            android:textSize="60sp"
                            android:textColor="@color/bottomtextcolor"
                            android:layout_below="@+id/img5"
                            android:text="@string/chatbot"
                            android:layout_centerHorizontal="true"/>
                    </RelativeLayout>
                </RelativeLayout>

                <RelativeLayout
                    android:layout_width="0px"
                    android:layout_height="match_parent"
                    android:translationZ="5dp"
                    android:layout_weight="1"
                    android:layout_marginLeft="8dp"
                    android:layout_marginRight="8dp"

                    >
                    <RelativeLayout
                        android:id="@+id/lay3"
                        android:layout_width="match_parent"
                        android:layout_height="match_parent"
                        android:background="@color/app_white"
                        android:visibility="visible">
                        <ImageView
                            android:id="@+id/img3"
                            android:layout_width="30dp"
                            android:layout_height="30dp"
                            android:padding="5dp"
                            android:layout_centerHorizontal="true"
                            android:layout_marginTop="5dp"
                            android:src="@drawable/my_health_tab_icon"/>
                        <com.nocon.spark.manager.FontFitTextView
                            android:layout_width="match_parent"
                            android:layout_height="wrap_content"
                            android:gravity="center"
                            android:layout_marginTop="1dp"
                            android:textSize="60sp"
                            android:textColor="@color/bottomtextcolor"
                            android:layout_below="@+id/img3"
                            android:text="@string/tab_health"
                            android:layout_centerHorizontal="true"
                            style="@style/tabtextstyle"/>
                    </RelativeLayout>
                </RelativeLayout>
                <RelativeLayout
                    android:layout_width="0px"
                    android:layout_height="match_parent"
                    android:translationZ="5dp"
                    android:layout_weight="1"
                    android:layout_marginLeft="8dp"
                    android:layout_marginRight="8dp"

                    >
                    <RelativeLayout
                        android:id="@+id/lay4"
                        android:layout_width="match_parent"
                        android:layout_height="match_parent"
                        android:background="@color/app_white"
                        android:visibility="visible">
                        <ImageView
                            android:id="@+id/img4"
                            android:layout_width="30dp"
                            android:layout_height="30dp"
                            android:padding="5dp"
                            android:layout_centerHorizontal="true"
                            android:layout_marginTop="5dp"
                            android:src="@drawable/account_tab_icon"
                            android:tint="@color/app_header"/>
                        <com.nocon.spark.manager.FontFitTextView
                            android:layout_width="match_parent"
                            android:layout_height="wrap_content"
                            android:textSize="60sp"
                            android:gravity="center"
                            android:layout_marginTop="1dp"
                            android:textColor="@color/bottomtextcolor"
                            android:layout_below="@+id/img4"
                            android:text="@string/tab_account"
                            android:layout_centerHorizontal="true"/>
                    </RelativeLayout>
                </RelativeLayout>
            </LinearLayout>
            <View
                android:layout_width="match_parent"
                android:layout_height="1dp"
                android:background="@color/app_graylight"/>
          </RelativeLayout>
        </android.support.design.widget.CoordinatorLayout>
    </android.support.design.widget.CoordinatorLayout>
</LinearLayout>

and this is my code

final NestedScrollView nested_content = (NestedScrollView) findViewById(R.id.nested_content);
    nested_content.setOnScrollChangeListener(new NestedScrollView.OnScrollChangeListener() {
        @Override
        public void onScrollChange(NestedScrollView v, int scrollX, int scrollY, int oldScrollX, int oldScrollY) {

            Log.e("ProductFragment","position button " + scrollX + "======= scrollY " + scrollY);
            if (scrollY < oldScrollY) { // up
                animateFab(true);
                animateSearchBar(true);
                colapseBar.setVisibility(View.GONE);
            }
            if (scrollY > oldScrollY) { // down

                animateFab(false);
                animateSearchBar(false);
                colapseBar.setVisibility(View.VISIBLE);

            }
        }
    });
3iL
  • 2,146
  • 2
  • 23
  • 47
Sharon Joshi
  • 498
  • 7
  • 19

0 Answers0