RecyclerView未填充android中的剩余空间

RecyclerView未填充android中的剩余空间,android,android-layout,Android,Android Layout,我正在学习android编程,并正在开发一个简单的“post”、“comment”、“like”类型的应用程序。一百万年来,我从未想过构建android应用程序最困难的部分是让布局正常工作。我有来自firebase数据库的所有信息,这很容易,但试图让布局看起来正确几乎是不可能的。我甚至试着从他们的firebase快速启动应用程序中复制/粘贴,firebase是一个做数据库工作的应用程序。但是,它不会填满这个区域。顶部看起来不错,但我有一个RecyclerView,它应该是重复该帖子的评论,它是重

我正在学习android编程,并正在开发一个简单的“post”、“comment”、“like”类型的应用程序。一百万年来,我从未想过构建android应用程序最困难的部分是让布局正常工作。我有来自firebase数据库的所有信息,这很容易,但试图让布局看起来正确几乎是不可能的。我甚至试着从他们的firebase快速启动应用程序中复制/粘贴,firebase是一个做数据库工作的应用程序。但是,它不会填满这个区域。顶部看起来不错,但我有一个RecyclerView,它应该是重复该帖子的评论,它是重复的,但它只是页面高度的一小部分,正如你在截图中看到的那样。我尝试过使用ScrollView、NestedScrollView,将RecyclerView放在相对的Layout、LinearLayout中,但没有任何效果。以下是视图的xml

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
                xmlns:tools="http://schemas.android.com/tools"
                android:layout_width="match_parent"
                android:layout_height="match_parent"
                android:paddingBottom="@dimen/activity_vertical_margin"
                android:paddingLeft="@dimen/activity_horizontal_margin"
                android:paddingRight="@dimen/activity_horizontal_margin"
                android:paddingTop="@dimen/activity_vertical_margin"
                tools:context="com.google.firebase.quickstart.auth.PostDetailActivity">

    <include
        android:id="@+id/post_author_layout"
        layout="@layout/include_post_author"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentLeft="true" />

    <include
        android:id="@+id/post_text_layout"
        layout="@layout/include_post_text"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentLeft="true"
        android:layout_below="@+id/post_author_layout"
        android:layout_marginLeft="5dp"
        android:layout_marginTop="10dp" />

    <LinearLayout
        android:id="@+id/comment_form"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:orientation="horizontal"
        android:layout_below="@+id/post_text_layout"
        android:layout_marginTop="20dp"
        android:weightSum="1.0">

        <EditText
            android:id="@+id/field_comment_text"
            android:layout_width="0dp"
            android:layout_weight="0.8"
            android:layout_height="wrap_content"
            android:maxLines="1"
            android:hint="Write a comment..."/>

        <Button
            android:id="@+id/button_post_comment"
            style="@style/Base.Widget.AppCompat.Button.Borderless"
            android:layout_width="0dp"
            android:layout_weight="0.2"
            android:layout_height="wrap_content"
            android:text="Post"/>

    </LinearLayout>

    <android.support.v7.widget.RecyclerView
        android:id="@+id/recycler_comments"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_below="@+id/comment_form"
        tools:listitem="@layout/item_comment" />

</RelativeLayout>

如果我将RecyclerView高度设置为与父项匹配,我仍然只能得到一条注释,因为每条注释现在都是父项的高度。

由于RecyclerView是一个动态布局,因此您希望始终填充父布局,而不是让它尝试包装其内容

<android.support.v7.widget.RecyclerView
    android:id="@+id/recycler_comments"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:layout_below="@+id/comment_form"
    tools:listitem="@layout/item_comment" />


Remove
android:paddingBottom
?是的,从根布局中移除填充。你是说在顶部的相对位置?我试过了,它只是“5dp”,所以它不会对你造成太大的伤害。你可以包括每行的布局吗?如果我这样做,它会使每条评论都有剩余空间的大小。因此,只有1条评论显示,然后你必须向下滚动更多的内容。我将向OP上传另一张图片,在RecyclerView的高度上与match_parent一起显示。等等,在另一个RecyclerView的每个项目中都有一个RecyclerView?如果没有,则说明您的帖子XML布局有问题。RecyclerView现在是正确的大小您是正确的。我完全忘记了item_comment.xml文件。这是一个相对高度的“匹配父母”。我能请你帮个小忙吗?有没有一种方法可以使文本输入和按钮强制到底部,同时允许其他内容滚动?RelativeLayout或ConstraintLayout会将视图/视图组锚定到底部。。。其他内容需要在底部视图之外的一些可滚动视图中