8

I'm using a recyclerview inside NestedScrollView and I want to pin my search bar to action bar after scrolling and recyclerview items must show under searchbar, I need to make lazy load for my recyclerview items (load next items from server after scrolling to end) for this I need to check recyclerview scroll change state and I can't do this perfectly when I use recyclerview inside nestedscrollview. I tried using nestedscrollview scroll state change listener and it doesn't give me what I want and doesn't work right.

Nested scroll view is not working if it's placed inside recyclerview. I have lazy load recyclerview but same layout contain other layouts like slider, menus then recyclerview. I want to scroll full layout and when recyclerview ends onscroll then onload execute to get more item from internet and load in recylerview.

Here you see my codes:

my layout xml code

 <android.support.design.widget.CoordinatorLayout android:layout_width="match_parent" android:layout_height="match_parent" android:background="@color/main_activity_background"> <android.support.design.widget.AppBarLayout android:id="@+id/app_bar_layout" android:layout_width="match_parent" android:layout_height="200dp" android:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar"> <android.support.design.widget.CollapsingToolbarLayout android:id="@+id/collapsing_toolbar" android:layout_width="match_parent" android:layout_height="match_parent" app:contentScrim="@color/colorPrimaryDark" app:expandedTitleTextAppearance="@style/TextAppearance.AppCompat.Headline" app:layout_scrollFlags="scroll|exitUntilCollapsed" app:titleEnabled="false"> <RelativeLayout android:layout_width="match_parent" android:layout_height="wrap_content"> <android.support.v4.view.ViewPager android:id="@+id/pager" android:layout_width="match_parent" android:layout_height="match_parent" android:layout_alignParentLeft="true" android:layout_alignParentStart="true" android:layout_alignParentTop="true" /> <RelativeLayout android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_alignParentBottom="true" android:layout_centerHorizontal="true" android:background="@drawable/bg_gradient" android:orientation="vertical" android:gravity="center_horizontal" android:paddingBottom="5dp" android:paddingLeft="@dimen/spacing_large" android:paddingRight="@dimen/spacing_large" android:paddingTop="@dimen/spacing_mxlarge"> <LinearLayout android:id="@+id/layout_dots" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_alignParentBottom="true" android:layout_gravity="center" android:gravity="center" android:orientation="horizontal" /> </RelativeLayout> </RelativeLayout> </android.support.design.widget.CollapsingToolbarLayout> </android.support.design.widget.AppBarLayout> <LinearLayout android:layout_width="match_parent" android:layout_height="wrap_content" android:orientation="vertical" app:layout_behavior="@string/appbar_scrolling_view_behavior"> <android.support.v7.widget.Toolbar android:id="@+id/toolbar" android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_gravity="bottom" app:contentInsetStartWithNavigation="0dp" app:layout_collapseMode="pin" app:popupTheme="@style/ThemeOverlay.AppCompat.Light" android:contentInsetLeft="0dp" android:contentInsetStart="0dp" app:contentInsetLeft="0dp" app:contentInsetStart="0dp" android:contentInsetRight="0dp" android:contentInsetEnd="0dp" app:contentInsetRight="0dp" app:contentInsetEnd="0dp"> <LinearLayout android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_marginLeft="5dp" android:layout_marginRight="5dp" android:focusable="true" android:focusableInTouchMode="true" android:background="@drawable/searchbox_stroke_bg" android:orientation="horizontal"> <EditText android:layout_width="0dp" android:layout_weight="0.9" android:layout_height="40dp" android:hint="@string/search" android:textDirection="locale" android:textAlignment="viewStart" android:drawablePadding="10dp" android:layout_gravity="start" android:paddingStart="15dp" android:textColor="@color/searchbox_stroke" android:maxLines="1" android:singleLine="true" android:maxLength="25" android:textSize="17sp" android:paddingEnd="5dp" android:background="@android:color/transparent" android:theme="@style/MainSearchEditTextTheme" android:drawableStart="@drawable/ic_search"/> <ImageView android:layout_width="0dp" android:layout_weight="0.1" android:layout_height="16dp" android:src="@drawable/ic_filter" android:layout_gravity="center_vertical" /> </LinearLayout> </android.support.v7.widget.Toolbar> <android.support.v4.widget.NestedScrollView android:layout_width="match_parent" android:layout_height="match_parent" android:clipToPadding="false" android:id="@+id/main_nested_scrollView" app:layout_behavior="@string/appbar_scrolling_view_behavior"> <RelativeLayout android:layout_width="match_parent" android:layout_height="match_parent" android:orientation="vertical"> <LinearLayout android:layout_width="match_parent" android:layout_height="match_parent" android:orientation="vertical"> <android.support.v7.widget.RecyclerView android:layout_width="match_parent" android:layout_height="match_parent" android:scrollbars="vertical" android:scrollingCache="true" android:nestedScrollingEnabled="false" android:id="@+id/main_recyclerview" android:layout_marginBottom="5dp"/> <LinearLayout android:layout_width="match_parent" android:layout_height="wrap_content" android:id="@+id/more_items_progress" android:visibility="gone"> <ProgressBar android:layout_width="match_parent" android:layout_height="wrap_content" android:id="@+id/progress_bar" android:indeterminate="true"/> </LinearLayout> </LinearLayout> <LinearLayout android:layout_width="wrap_content" android:layout_height="wrap_content" android:id="@+id/lyt_progress" android:layout_centerInParent="true" android:layout_marginTop="100dp" android:orientation="vertical"> <com.armanjafari.raimon.widget.ViewLoadingDotsBounce android:layout_width="50dp" android:layout_height="40dp" android:layout_centerHorizontal="true" android:background="@color/colorAccent"> </com.armanjafari.raimon.widget.ViewLoadingDotsBounce> </LinearLayout> </RelativeLayout> </android.support.v4.widget.NestedScrollView> </LinearLayout> </android.support.design.widget.CoordinatorLayout> 

My code to check scroll state and it didn't work

 nested_content.setOnScrollChangeListener(new NestedScrollView.OnScrollChangeListener() { @Override public void onScrollChange(NestedScrollView v, int scrollX, int scrollY, int oldScrollX, int oldScrollY) { if (scrollY < oldScrollY) { // up ((MainActivity)getActivity()).animateNavigation(false); } if (scrollY > oldScrollY) { // down ((MainActivity)getActivity()).animateNavigation(true); } if (scrollY == ( v.getChildAt(0).getMeasuredHeight() - v.getMeasuredHeight() )) { if (!is_loading) { if (current_page < all_pages) { //not work right scroll state } } } } }); 
0

1 Answer 1

0

i got the answer, if any one have my problem see below...

for detect nestedscrollview is at end correctly use this code:

nested_content.setOnScrollChangeListener(new NestedScrollView.OnScrollChangeListener() { @Override public void onScrollChange(NestedScrollView v, int scrollX, int scrollY, int oldScrollX, int oldScrollY) { if (scrollY < oldScrollY) { // up ((MainActivity)getActivity()).animateNavigation(false); } if (scrollY > oldScrollY) { // down ((MainActivity)getActivity()).animateNavigation(true); } View view = (View) nested_content.getChildAt(nested_content.getChildCount() - 1); int diff = (view.getBottom() - (nested_content.getHeight() + nested_content .getScrollY())); if (diff == 0) { if (merchantList.size()>0) { if (!is_loading) { if(current_page<=all_pages) { // nestedscrollview at end getMerchants(current_page); } } } } } }); 
Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.