RecyclerView不尊重height = wrap_content?

Lit*_*ild 5 android android-support-library android-recyclerview

我有一个聊天屏幕,其中包含两个视图:一个用于显示上一个聊天的回收站视图和一个自定义视图,其中包含一个编辑文本,一个发送按钮和另一个回收站视图,让用户可以选择要发送的其他内容,如照片等.视图称为"面板".

所以,我的聊天活动有以下布局:

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout
    android:orientation="vertical"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    xmlns:android="http://schemas.android.com/apk/res/android">

    <chat.example.app.widget.Panel
        style="@style/PanelStyle"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_gravity="bottom|center"
        android:id="@+id/panel" />

    <android.support.v7.widget.RecyclerView
        android:background="@android:color/holo_red_dark"
        android:layout_margin="@dimen/activity_horizontal_margin"
        android:scrollbars="vertical"
        android:id="@+id/previous_chat"
        android:layout_above="@id/panel"
        android:layout_alignParentTop="true"
        android:layout_width="match_parent"
        android:layout_height="wrap_content" />

</RelativeLayout>
Run Code Online (Sandbox Code Playgroud)

我的"面板"视图具有以下布局:

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:background="@android:color/white">
    <RelativeLayout
        android:id="@+id/staging_area_root"
        android:layout_gravity="center"
        android:gravity="center"
        android:paddingLeft="5dp"
        android:layout_width="match_parent"
        android:layout_height="wrap_content">
        <!-- Chat box and send -->
    </RelativeLayout>
    <!-- THIS GUY IS PROBLEMATIC -->
    <android.support.v7.widget.RecyclerView
        android:id="@+id/card_set"
        android:layout_margin="15dp"
        android:layout_below="@id/staging_area_root"
        android:background="@android:color/holo_blue_bright"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"/>
</RelativeLayout>  
Run Code Online (Sandbox Code Playgroud)

问题是回收者视图Panel吞噬了整个屏幕空间.所以我看到的是来自Panel类的有问题的回收者视图.

这些回收者视图都已LinearLayoutManager分配给他们.还没有适配器.

我有最新的支持库build.gradle:

compile 'com.android.support:recyclerview-v7:23.2.0'  
Run Code Online (Sandbox Code Playgroud)

并浏览最新的android开发者博客文章:

此版本为LayoutManager API带来了令人兴奋的新功能:自动测量!这允许RecyclerView根据其内容的大小调整自身大小.这意味着现在可以使用以前不可用的方案,例如使用WRAP_CONTENT作为RecyclerView的维度.您会发现所有内置的LayoutManagers现在都支持自动测量.

我错过了什么吗?

更新1:

我在有问题的回收者视图中添加了一个适配器,其中包含0个项目.仍然没有解决方案

Update2:
截图:

在此输入图像描述

Ale*_*end 8

从23.2 RecyclerView onMeasure()电话中获取的代码段:

if (mLayout.mAutoMeasure) {
        final int widthMode = MeasureSpec.getMode(widthSpec);
        final int heightMode = MeasureSpec.getMode(heightSpec);
        final boolean skipMeasure = widthMode == MeasureSpec.EXACTLY
                && heightMode == MeasureSpec.EXACTLY;
        mLayout.onMeasure(mRecycler, mState, widthSpec, heightSpec);
        if (skipMeasure || mAdapter == null) {
            return;
        }
        if (mState.mLayoutStep == State.STEP_START) {
            dispatchLayoutStep1();
        }
        // set dimensions in 2nd step. Pre-layout should happen with old dimensions for
        // consistency
        mLayout.setMeasureSpecs(widthSpec, heightSpec);
        mState.mIsMeasuring = true;
        dispatchLayoutStep2();

        // now we can get the width and height from the children.
        mLayout.setMeasuredDimensionFromChildren(widthSpec, heightSpec);

        // if RecyclerView has non-exact width and height and if there is at least one child
        // which also has non-exact width & height, we have to re-measure.
        if (mLayout.shouldMeasureTwice()) {
            mLayout.setMeasureSpecs(
                    MeasureSpec.makeMeasureSpec(getMeasuredWidth(), MeasureSpec.EXACTLY),
                    MeasureSpec.makeMeasureSpec(getMeasuredHeight(), MeasureSpec.EXACTLY));
            mState.mIsMeasuring = true;
            dispatchLayoutStep2();
            // now we can get the width and height from the children.
            mLayout.setMeasuredDimensionFromChildren(widthSpec, heightSpec);
        }
    }
Run Code Online (Sandbox Code Playgroud)

mLayout.setMeasuredDimensionFromChildren()呼叫将根据孩子的大小进行自动测量RecyclerView.意思RecyclerView.Adapter是,触发自动测量需要有1个或更多个孩子的有效.