NestedScrollView+RecyclerView+适配器中包含EditText布局自动滑动问题

在日常开发中,NestedScrollView嵌套RecyclerView时,RecyclerView适配器中包含EditText时,用户在操作EditText时布局会自动滑动,导致用户交互问题。我在一个项目中也遇到类似的问题,网上搜索一大堆禁止这个滑动事件那个滑动事件的。试了一大堆,下面这个方法成功解决了我的问题,分享给大家。
1.、自定义NestedScrollView
       代码:
           public class NoNestedScrollViewextends NestedScrollView{

                public NoNestedScrollView(@NonNull Context context) {

                    super(context);

                }

            public NoNestedScrollView(@NonNull Context context,@Nullable AttributeSet attrs) {

                    super(context, attrs);

            }

            public NoNestedScrollView(@NonNull Context context,@Nullable AttributeSet attrs,int defStyleAttr) {

                    super(context, attrs, defStyleAttr);

            }

            @Override

            protected int computeScrollDeltaToGetChildRectOnScreen(Rect rect) {

                    return 0;

                }

            }
2、修改xml文件
    
       <com.yym.ui.view.NoNestedScrollView

            android:layout_width="match_parent"

            android:layout_height="wrap_content"

            android:layout_below="@+id/rl_time"

            android:overScrollMode="never"

            android:fadingEdge="none"

            android:scrollbars="none">

            <LinearLayout

                android:layout_width="match_parent"

                android:layout_height="match_parent"

                android:orientation="vertical">

            <androidx.recyclerview.widget.RecyclerView

                android:id="@+id/recyclerView"

                android:layout_marginHorizontal="35dp"

                android:layout_width="match_parent"

                android:overScrollMode="never"

                android:layout_height="wrap_content" />

      <!--可以多个RecyclerView-->

</LinearLayout>

  </com.yym.ui.view.NoNestedScrollView>

        

    
     

©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。
禁止转载,如需转载请通过简信或评论联系作者。

推荐阅读更多精彩内容