Android使用不可滑动RecyclerView条目显示不全问题(只显示两个item)


前言

在写一个ScrollView包裹RecyclerView的功能时,要求RecyclerView包裹数据长度且不可滑动,设置不可滑动后发现item只展示了两条数据,删掉不可滑动代码后数据滑动显示则正常。


二、解决步骤

1.xml布局

代码如下(示例):

    <androidx.core.widget.NestedScrollView
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:fillViewport="true">

        <LinearLayout
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:descendantFocusability="blocksDescendants"
            android:orientation="vertical">

           
            <androidx.recyclerview.widget.RecyclerView
                android:id="@+id/rv_list"
                android:layout_width="match_parent"
                android:layout_height="match_parent"
                android:layout_above="@+id/llKeborad"
                android:layout_below="@+id/rl_top"
                android:fadingEdge="none" />

        </LinearLayout>
    </androidx.core.widget.NestedScrollView>

此处注意最好使用NestedScrollView,并且在RecyclerView的父布局中加入
android:descendantFocusability="blocksDescendants"属性,也就是示例中的LinearLayout中添加

2.java代码示例

代码如下(示例):

 mRecyclerView.setHasFixedSize(true);
        mRecyclerView.setNestedScrollingEnabled(false);
        LinearLayoutManager linearLayoutManager = new LinearLayoutManager(getActivity()) {
            @Override
            public boolean canScrollVertically() {
                return false;
            }
        };
        mRecyclerView.setLayoutManager(linearLayoutManager);
        mRecyclerView.setNestedScrollingEnabled(false);//禁止滑动

以上代码设置RecyclerView不可滑动,配合xml就可以解决RecyclerView条目显示不全问题(只显示两个item)得问题了


总结

以上就是今天要讲的内容,本文仅仅简单介绍了使用不可滑动RecyclerView条目显示不全问题(只显示两个item)的解决方法。

  • 3
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

木易明~

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值