简体   繁体   English

检查nestedscrollview中的recyclelerview滚动状态

[英]Check recyclerview scroll state inside nestedscrollview

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. 我在NestedScrollView中使用了recyclerview,我想在滚动后将搜索栏固定到操作栏,并且必须在搜索栏下显示recyclelerview项目,我需要为我的recyclerview项目进行延迟加载(滚动到结束后从服务器加载下一项)为此,我需要检查recyclerview滚动更改状态,当我在nestedscrollview中使用recyclelerview时,我无法做到这一点。 I tried using nestedscrollview scroll state change listener and it doesn't give me what I want and doesn't work right. 我尝试使用nestedscrollview滚动状态更改侦听器,它不会给我我想要的东西,也不能正常工作。

Nested scroll view is not working if it's placed inside recyclerview. 如果将嵌套滚动视图放在recyclerview中,则它不起作用。 I have lazy load recyclerview but same layout contain other layouts like slider, menus then recyclerview. 我有懒惰加载recyclelerview但相同的布局包含其他布局,如滑块,菜单然后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. 我想滚动完整的布局,当recyclerview结束onscroll然后onload执行从Internet获取更多项目并加载recylerview。

Here you see my codes: 在这里你看到我的代码:

my layout xml code 我的布局xml代码

 <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
                    }

                }

            }
        }
    });

i got the answer, if any one have my problem see below... 我得到了答案,如果有人有我的问题,请看下面...

for detect nestedscrollview is at end correctly use this code: 检测nestedscrollview是否正确使用此代码:

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);
                        }
                    }
                }

            }
        }
    });

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 NestedScrollView内的RecyclerView比RecyclerView滚动得更快 - RecyclerView inside NestedScrollView scroll faster than RecyclerView NestedScrollView中的RecyclerView - 不需要的滚动开始 - RecyclerView inside NestedScrollView - unwanted scroll to begin LinearLayout 和 NestedScrollView 中的 RecyclerView - 如何滚动到某个位置的项目顶部? - RecyclerView inside LinearLayout and NestedScrollView - How to scroll to top of item on a certain position? NestedScrollView里面没有使用Recyclerview - NestedScrollView not fling with Recyclerview inside RecyclerView 不在 NestedScrollView 内滚动 - RecyclerView not scrolling inside NestedScrollView NestedScrollView 内的 RecyclerView 问题 - RecyclerView inside NestedScrollView issue 在nestedscrollview的recyclerview内部的recyclerview的notifyDataChanged上,外部recyclerview滚动到顶部 - On notifyDataChanged of recyclerview inside a recyclerview in a nestedscrollview the outer recyclerview scrolls to top 使用NestedScrollView中的Multiple Recyclerview不会发生回收 - View Recycling not happens with Multiple Recyclerview inside NestedScrollView 嵌套滚动视图中的 recyclerview addOnScrollListener (endless scrolllistener) - recyclerview inside nestedscrollview addOnScrollListener (endless scrolllistener) 如何在 NestedScrollView 中限制 RecyclerView 的高度 - How to limit the height of a RecyclerView inside a NestedScrollView
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM