Android RecyclerView 限制子条目数量

本文介绍如何在Android的RecyclerView中限制当前页面显示的子条目数量,最多展示5个,超出部分点击跳转查看。内容包括XML布局、Adapter的实现细节,以及遇到的问题,如根布局限制和ScrollView嵌套问题。
摘要由CSDN通过智能技术生成

正常列表展示:
recyclerview正常.gif

我们要限制显示的item数量效果:
recyclerview限制.gif

两个比较不难发现虽然都是能滑动,但是展示在当前页面的列表数量不一样。

最近玩蓝牙有这个需求我才知道这玩意还能限制条目。。。
蓝牙展示需求

就是最多展示5,多余的点击跳转展示更多。。。死数据研究中

好了废话不多说,回归正题
感谢大佬:https://blog.csdn.net/unknown_315/article/details/88297132
以上网址亲测了下可以实现的,效果上面。

就写了个适配器
XML

<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    tools:context=".MainActivity">

   <androidx.recyclerview.widget.RecyclerView
       android:id="@+id/recycler"
       android:layout_width="match_parent"
       android:layout_height="match_parent"/>

</androidx.constraintlayout.widget.ConstraintLayout>

Adapter item XML

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="wrap_conte
  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值