约束布局内的回收器视图问题 [英] Issue with recycler view inside constraint layout

本文介绍了约束布局内的回收器视图问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试基于复杂布局创建底部工作表对话框。 我要实现的是一个带有标题布局的对话框、一个带有元素列表的回收器视图和一个带有几个按钮的底部栏。 以下是我的代码:

<?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">

    <android.support.constraint.ConstraintLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:orientation="vertical">

        <!-- Layout injected inside this linear layout container programmatically -->
        <LinearLayout
            android:id="@+id/header_dialog_container"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:orientation="vertical"
            app:layout_constraintBottom_toTopOf="@id/form_dialog_recycler_view"
            app:layout_constraintTop_toTopOf="parent" />

        <android.support.v7.widget.RecyclerView
            android:id="@+id/form_dialog_recycler_view"
            android:layout_width="match_parent"
            android:layout_height="0dp"
            android:scrollbars="vertical"
            app:layout_behavior="@string/appbar_scrolling_view_behavior"
            app:layout_constraintBottom_toTopOf="@id/bottom_sheet_container_buttons"
            app:layout_constraintEnd_toEndOf="parent"
            app:layout_constraintStart_toStartOf="parent"
            app:layout_constraintTop_toBottomOf="@id/header_dialog_container" />

        <LinearLayout
            android:id="@+id/bottom_sheet_container_buttons"
            android:layout_width="match_parent"
            android:layout_height="60dp"
            android:orientation="horizontal"
            app:layout_constraintBottom_toBottomOf="parent">

            <Button
                android:id="@+id/dialog_sheet_button_reset"
                style="@style/ActionSheetTitle"
                android:layout_width="0dp"
                android:layout_height="60dp"
                android:layout_weight="0.5"
                android:background="@color/bottomBarContainerColor"
                android:text="@string/general_reset"
                android:textColor="@color/dangerColor" />

            <Button
                android:id="@+id/dialog_sheet_button_close"
                style="@style/ActionSheetTitle"
                android:layout_width="0dp"
                android:layout_height="60dp"
                android:layout_weight="0.5"
                android:background="@color/bottomBarContainerColor"
                android:text="@string/general_close" />

        </LinearLayout>
    </android.support.constraint.ConstraintLayout>
</layout>

遗憾的是,我的回收器视图高度始终等于零。我试图将android:layout_height="0dp"更改为android:layout_height="wrap_content",但不出所料,它位于底部容器的下方。我错过了什么吗?

推荐答案

如果在ConstraintLayout内,请尝试app:layout_constraintHeight_default="wrap"RecyclerView

这篇关于约束布局内的回收器视图问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆