RecyclerView不在ConstraintLayout的TextView下显示

问题描述 投票:0回答:2

我有这个布局,我使用了ConstraintLayout。代码如下

<?xml version="1.0" encoding="utf-8"?>

<androidx.constraintlayout.widget.ConstraintLayout
    android:id="@+id/main_content"
    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=".ui.main.MainActivity">

    <TextView
    android:id="@+id/txtVwCount"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:text="the count is: 5"
    app:layout_constraintEnd_toEndOf="parent"
    app:layout_constraintStart_toStartOf="parent"
    app:layout_constraintTop_toTopOf="parent"
    />

    <view
    android:id="@+id/rclrVw"
    class="androidx.recyclerview.widget.RecyclerView"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    app:layout_constraintTop_toBottomOf="@id/txtVwCount"
    app:layout_constraintBottom_toBottomOf="parent"
    app:layout_constraintEnd_toEndOf="parent"
    app:layout_constraintStart_toStartOf="parent"
       />



    <com.google.android.material.floatingactionbutton.FloatingActionButton
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:src="@drawable/ic_plus"
    android:layout_margin="16dp"
    app:layout_anchor="@id/rclrVw"
    android:clickable="true"
    android:onClick="addNewTodo"
    app:layout_constraintRight_toRightOf="parent"
    app:layout_constraintBottom_toBottomOf="parent"/>


</androidx.constraintlayout.widget.ConstraintLayout>

截屏:

enter image description here

不是应该在顶部显示textview还是在textView下方显示recyclerView吗?它们为什么重叠?

android android-layout android-constraintlayout
2个回答
2
投票

只需添加以下两行:
android:layout_height =“ 0dp”

app:layout_constraintStart_toEndOf =“ @ + id / txtVwCount”


0
投票
© www.soinside.com 2019 - 2024. All rights reserved.