ConstraintLayout下RecyclerView不显示

博客讲述了作者在使用ConstraintLayout时遇到RecyclerView不显示的问题。尽管RecyclerView占据了整个屏幕空间,但其items无法正常显示。通过将RecyclerView的宽高改为0dp,问题得到解决,但作者对这一bug的原因仍不清楚,期待进一步的解释。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

昨天遇到的一个巨坑的Bug,就下面这个简单的布局,在约束布局中把RecyclerView的宽高都设置为match_parent,然后,然后神奇的事情发生了,RecyclerView很正常的充满了整个屏幕,但是他的item一个都显示不出来,查了半天,其他地方一点问题都没有。

<?xml version="1.0" encoding="utf-8"?>
<android.support.constraint.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="com.qg.gankio.ui.TodayActivity">

    <com.qg.gankio.widget.LoadMoreRecyclerView
        android:id="@+id/todayList"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:layout_marginBottom="0dp"
        android:layout_marginEnd="0dp"
        android:layout_marginStart="0dp"
        android:layout_marginTop="0dp"
        app:layout_constraintBottom_toBottomOf="parent"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintTop_toTopOf="parent" />

</android.support.constraint.ConstraintLayout>

最后突发奇想把RecyclerView的宽高设置为0dp,他就神奇的好了,小白暂时搞不清楚为什么会有这样的bug,等待高人的指点,谢谢。

评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值