在RecyclerView之后,使空视图占用剩余空间?

Tar*_*riq 10 android android-layout android-xml

我正在尝试制作一个有色的空视图占用RecyclerView之后的剩余空间.我看过不同的StackOverflow解决方案,但没有任何效果.基本上我想要这样的东西:

________________________
|                       |
|                       |
|                       |
|    Recycler view      |
|                       |
|  -------------------  |
|    colored empty view |
|                       |
|                       |
|                       |
|                       |
|                       |
_________________________

It should shrink as the RecyclerView grows. 

________________________
|                       |
|                       |
|                       |
|    Recycler view      |
|                       |
|                       |
|                       |
|                       |
|                       |
|  -------------------  |
|    colored empty view |
|                       |
|                       |
_________________________
Run Code Online (Sandbox Code Playgroud)

但是,如果RecyclerView超过一个屏幕的价值,则应该没有空视图.这是我到目前为止所拥有的:

 <?xml version="1.0" encoding="utf-8"?>
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:fab="http://schemas.android.com/apk/res-auto"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:id="@+id/bla_bla_layout">


    <android.support.v7.widget.RecyclerView
        android:id="@+id/bla_bla_recyclerview"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"/>

    <View
        android:background="@color/grayBackground"
        android:layout_gravity="bottom"
        android:layout_width="match_parent"
        android:layout_height="match_parent"/>

    <com.melnykov.fab.FloatingActionButton
        android:id="@+id/fab"
        android:contentDescription="@string/add_bla"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_gravity="bottom|right"
        android:layout_margin="16dp"
        android:src="@drawable/add_bla_icon"
        fab:fab_colorNormal="@color/primary"
        fab:fab_colorPressed="@color/primary_pressed"
        fab:fab_colorRipple="@color/ripple" />

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

编辑 这不是上述问题的重复,如果您同时阅读这两个问题,您可以看到这一点.我的问题的解决方案应该是纯xml,基于布局."空视图"我的意思是现有的RecyclerView下面只有一些彩色矩形,而不是当RecylerView中没有数据时实际上显示"空视图"的文本视图.

Dro*_*Dev 6

Recycler视图在运行时计算其高度,我们使用LinearLayoutManager指定其高度和宽度.

但问题是,现在LinearLayoutManager不支持wrap_content,它总是使用match_parent来表示它的高度.

所以你必须使用这个LinearLayoutManager而不是android.support.v7.widget.LinearLayoutManager.

复制包中的java类,并使用如下所示,

LinearLayoutManager linearLayoutManager = new LinearLayoutManager(this,
            LinearLayoutManager.VERTICAL, false);
recyclerView.setLayoutManager(linearLayoutManager);
// if it has fixed size
recyclerView.setHasFixedSize(true);
Run Code Online (Sandbox Code Playgroud)

我测试了它,它可以根据需要进行测试.