ScrollView嵌套RecyclerView滚动冲突

举报
yd_221104950 发表于 2020/12/02 23:30:47 2020/12/02
【摘要】 ScrollView嵌套RecyclerView滚动冲突 1. 概述2.布局3.MainActivity 1. 概述 使用ScrollView嵌套RecyclerView会造成滚动冲突。这个问题可以使用NestedScrollView来解决。 2.布局 <?xml version="1.0" encoding="utf-8"?> <LinearL...

ScrollView嵌套RecyclerView滚动冲突

1. 概述

使用ScrollView嵌套RecyclerView会造成滚动冲突。这个问题可以使用NestedScrollView来解决。

2.布局

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:id="@+id/rl_root" android:layout_width="match_parent" android:layout_height="match_parent" android:orientation="vertical"> <androidx.core.widget.NestedScrollView android:layout_width="match_parent" android:layout_height="match_parent"> <LinearLayout android:layout_width="match_parent" android:layout_height="wrap_content" android:orientation="vertical" android:paddingLeft="5dp" android:paddingRight="5dp"> <LinearLayout android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_marginStart="10dp" android:layout_marginLeft="10dp" android:layout_marginTop="10dp" android:gravity="center_vertical" android:orientation="horizontal"> <TextView android:id="@+id/textView1" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_gravity="top|left" android:text="单号:" /> <androidx.recyclerview.widget.RecyclerView android:id="@+id/rv_num" android:layout_width="match_parent" android:layout_height="200dp" android:minHeight="20dp" /> </LinearLayout> <TextView android:layout_width="wrap_content" android:layout_height="wrap_content" android:textColor="@android:color/black" android:text="最多可上传4张"/> <TextView android:layout_width="wrap_content" android:layout_height="wrap_content" android:textColor="@android:color/black" android:text="最多可上传4张"/> ... </LinearLayout> </androidx.core.widget.NestedScrollView>
</LinearLayout>



  
 
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 23
  • 24
  • 25
  • 26
  • 27
  • 28
  • 29
  • 30
  • 31
  • 32
  • 33
  • 34
  • 35
  • 36
  • 37
  • 38
  • 39
  • 40
  • 41
  • 42
  • 43
  • 44
  • 45
  • 46
  • 47
  • 48
  • 49
  • 50
  • 51
  • 52
  • 53
  • 54
  • 55
  • 56
  • 57
  • 58

3.MainActivity

public class MainActivity extends AppCompatActivity { private RecyclerView mRV; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); // 运单号列表 mRV = (RecyclerView) findViewById(R.id.rv_num); // 防止卡顿 mRV.setHasFixedSize(true); mRV.setNestedScrollingEnabled(true); LinearLayoutManager linearLayoutManager = new LinearLayoutManager(this); linearLayoutManager.setSmoothScrollbarEnabled(true); // 取消recycleview的滑动 mRV.setLayoutManager(linearLayoutManager); List<String> list = new ArrayList<>(); for(int i = 0; i < 30;i++){ list.add("020-88888"+i); } mRV.setAdapter(new RVAdapter(list)); }
}

  
 
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 23
  • 24

Demo下载

文章来源: blog.csdn.net,作者:WongKyunban,版权归原作者所有,如需转载,请联系作者。

原文链接:blog.csdn.net/weixin_40763897/article/details/106500067

【版权声明】本文为华为云社区用户转载文章,如果您发现本社区中有涉嫌抄袭的内容,欢迎发送邮件进行举报,并提供相关证据,一经查实,本社区将立刻删除涉嫌侵权内容,举报邮箱: cloudbbs@huaweicloud.com
  • 点赞
  • 收藏
  • 关注作者

评论(0

0/1000
抱歉,系统识别当前为高风险访问,暂不支持该操作

全部回复

上滑加载中

设置昵称

在此一键设置昵称,即可参与社区互动!

*长度不超过10个汉字或20个英文字符,设置后3个月内不可修改。

*长度不超过10个汉字或20个英文字符,设置后3个月内不可修改。

举报
请填写举报理由
0/200