NetstedScrollView RecyclerView滑动中出现问题记录

版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/u013187628/article/details/84064838
1. RecyclerView 不能fling,滑动不顺畅

解决办法:

        ViewCompat.setNestedScrollingEnabled(recyclerView, false);  
2.RecyclerView 在notifyDataSetChanged()后自动滚动的问题
       <android.support.v4.widget.NestedScrollView
                android:id="@+id/scrollView"
                android:layout_width="match_parent"
                android:layout_height="match_parent">

                <LinearLayout
                    android:id="@+id/ll_scroll_container"
                    android:layout_width="match_parent"
                    android:layout_height="match_parent"
                    android:descendantFocusability="blocksDescendants"
                    android:orientation="vertical">

                    <TextView
                        android:id="@+id/detail_tip"
                        android:layout_width="wrap_content"
                        android:layout_height="wrap_content"
                        android:paddingLeft="15dp"
                        android:paddingTop="20dp"
                        android:paddingRight="15dp"
                        android:paddingBottom="20dp"
                        android:textSize="13sp" />

                    <android.support.v7.widget.RecyclerView
                        android:id="@+id/recyclerView"
                        android:layout_width="match_parent"
                        android:layout_height="match_parent"
                        android:divider="#00000000"
                        android:dividerHeight="0dip"
                        android:overScrollMode="never"
                        android:listSelector="@android:color/transparent"
                        android:scrollbars="none" />
                </LinearLayout>
            </android.support.v4.widget.NestedScrollView>

如上代码,会出现在noifyDataSetChanged()之后,自动定位到RecyclerView的顶部,上方的detail_tip TextView 没有在屏幕中展示。 上图中的代码问题已经解决。
解决办法是添加了:

			//添加到RecyclerView的父布局中
                   android:descendantFocusability="blocksDescendants"
                   //添加到RecyclerView中
                   android:overScrollMode="never"

解释:

android:descendantFocusability :Defines the relationship between the ViewGroup and its descendants when looking for a View to take focus.
翻译:定义ViewGroup和其子View的关系来确定需要一个View获取焦点时,哪个View来获取当前的焦点。

猜你喜欢

转载自blog.csdn.net/u013187628/article/details/84064838