首页 > 解决方案 > Android 垂直 RecyclerView 在 ConstraintLayout 内的高度变为 0;

问题描述

在 android studio 的预览中,应用程序很好,但在运行时高度变为零;这是布局的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:id="@+id/filemaneger_id"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:background="#f6f6f6"
    android:focusable="true"
    android:layoutDirection="ltr">

    <androidx.recyclerview.widget.RecyclerView
        android:id="@+id/recycv"
        android:layout_width="0dp"
        android:layout_height="0dp"
        android:background="#ffffff"
        android:scrollbars="vertical"
        app:layout_constraintBottom_toBottomOf="parent"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintTop_toTopOf="parent" />

</androidx.constraintlayout.widget.ConstraintLayout>

顺便说一下,该应用程序在相对布局中运行良好;

标签: androidandroid-recyclerviewandroid-constraintlayoutandroidx

解决方案


推荐阅读