微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

如何使用 RecyclerVeiw 填充屏幕的其余部分?

如何解决如何使用 RecyclerVeiw 填充屏幕的其余部分?

在下图中,您可以看到 RecyclerView 延伸到我的屏幕下方。这就是我看不到最后一项的原因。我只希望我的 RecyclerView 可以滚动。

我可以只用 xml 来解决这个问题吗?

这是my_fragment.xml

<?xml version="1.0" encoding="utf-8"?>
<layout 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"
    tools:context=".screens.mijnhuis.HuisFragment">

    <data>
        <import type="android.view.View"/>
        <import type="android.text.TextUtils"/>
        <variable
            name="varName"
            type="be.vives.ti.summatieve.screens.mijnhuis.HuisVM"/>
    </data>

    <androidx.constraintlayout.widget.ConstraintLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:scrollbars="vertical">

        <TextView
            android:id="@+id/adres"
            style="@style/MainText"
            android:layout_width="wrap_content"
            android:layout_height="100dp"
            android:layout_marginTop="50dp"
            android:text='@{TextUtils.isEmpty(varName.huis.straat) ? "U heeft nog geen adres ingesgteld":@string/adres(varName.huis.straat,varName.huis.nummer,varName.huis.gemeente,varName.huis.postcode)}'
            android:textAlignment="center"
            app:layout_constraintEnd_toEndOf="parent"
            app:layout_constraintStart_toStartOf="parent"
            app:layout_constraintTop_toTopOf="parent" />

        <Button
            android:id="@+id/button2"
            style="@style/btn"
            android:layout_marginStart="20dp"
            android:onClick="@{() -> varName.btnNavToEditHuis()}"
            android:text="@string/edit"
            app:layout_constraintStart_toEndOf="@+id/button3"
            app:layout_constraintTop_toBottomOf="@+id/adres" />

        <Button
            android:id="@+id/button3"
            style="@style/btn"
            android:layout_marginEnd="110dp"
            android:onClick="@{() -> varName.btnNavToAdd()}"
            android:text="@string/addDak"
            app:layout_constraintEnd_toEndOf="parent"
            app:layout_constraintStart_toStartOf="parent"
            app:layout_constraintTop_toTopOf="@+id/button2" />

        <androidx.recyclerview.widget.RecyclerView
            android:id="@+id/list"
            android:name="be.vives.ti.summatieve.HuisFragment"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_marginStart="10dp"
            android:layout_marginEnd="10dp"
            app:layoutManager="linearlayoutmanager"
            app:layout_constraintEnd_toEndOf="parent"
            app:layout_constraintHorizontal_bias="0.0"
            app:layout_constraintStart_toStartOf="parent"
            app:layout_constraintTop_toBottomOf="@+id/button3"
            tools:context=".screens.mijnHuis.HuisFragment"
            tools:listitem="@layout/detail_dak" />

    </androidx.constraintlayout.widget.ConstraintLayout>
</layout>

在这图片中,您可以看到我的 RecyclerView 在我的屏幕下方延伸。

Image

解决方法

欢迎 Bjop,试试这个:

<androidx.recyclerview.widget.RecyclerView
        android:id="@+id/list"
        android:name="be.vives.ti.summatieve.HuisFragment"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:layout_marginStart="10dp"
        android:layout_marginEnd="10dp"
        app:layoutManager="LinearLayoutManager"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintHorizontal_bias="0.0"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintTop_toBottomOf="@+id/button3"
        tools:context=".screens.mijnHuis.HuisFragment"
        tools:listitem="@layout/detail_dak" />
,

您缺少底部约束。尝试这样设置:

<androidx.recyclerview.widget.RecyclerView
        android:id="@+id/list"
        android:name="be.vives.ti.summatieve.HuisFragment"
        android:layout_width="match_parent"
        android:layout_height="0dp"
        android:layout_marginStart="10dp"
        android:layout_marginEnd="10dp"
        app:layoutManager="LinearLayoutManager"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintHorizontal_bias="0.0"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintTop_toBottomOf="@+id/button3"
        app:layout_constraintBottom_toBottomOf="parent"
        tools:context=".screens.mijnHuis.HuisFragment"
        tools:listitem="@layout/detail_dak" />

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。