NestedScrollView嵌套横向滑动RecyclerView
时间: 2023-12-17 08:28:23 浏览: 163
以下是在NestedScrollView中嵌套横向滑动RecyclerView的方法:
1.在XML布局文件中添加NestedScrollView和RecyclerView:
```xml
<androidx.core.widget.NestedScrollView
android:layout_width="match_parent"
android:layout_height="match_parent">
<androidx.recyclerview.widget.RecyclerView
android:id="@+id/recyclerView"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal" />
</androidx.core.widget.NestedScrollView>
```
2.在代码中设置RecyclerView的LayoutManager为LinearLayoutManager,并将其方向设置为横向:
```java
RecyclerView recyclerView = findViewById(R.id.recyclerView);
LinearLayoutManager layoutManager = new LinearLayoutManager(this, LinearLayoutManager.HORIZONTAL, false);
recyclerView.setLayoutManager(layoutManager);
```
3.给RecyclerView配置属性setNestedScrollingEnabled(false),设置嵌套滑动不可用:
```java
recyclerView.setNestedScrollingEnabled(false);
```
阅读全文
相关推荐
















