如何在ConstraintLayout中wrap_content或“填充可用空间”

Ato*_*ean 5 android android-layout android-recyclerview android-constraintlayout

我有这样的布局:

<android.support.constraint.ConstraintLayout 
android:layout_width="match_parent"
android:layout_height="match_parent">
    ... 
    <FrameLayout
    android:id="@+id/content"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:layout_marginTop="200dp"
    app:layout_constraintEnd_toEndOf="parent"
    app:layout_constraintStart_toStartOf="parent"
    app:layout_constraintBottom_toBottomOf="parent" />
</android.support.constraint.ConstraintLayout >
Run Code Online (Sandbox Code Playgroud)

此recyclerview被添加到“ id / content”框架布局中

<android.support.v7.widget.RecyclerView 
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="@color/white"
android:layout_gravity="bottom"
android:layout_marginLeft="8dp"
android:layout_marginRight="8dp"
app:layoutManager="LinearLayoutManager" />
Run Code Online (Sandbox Code Playgroud)

将recyclerview放置在屏幕底部具有理想的效果。

在此处输入图片说明

当recyclerview中有许多视图持有者时,就会出现问题。我想在顶部留一些空间以查看地图(200dp的余量)。我已经尝试了很多方法,但似乎找不到一个理想的解决方案。本质上,我想要的是recyclerview将wrap_content直到该内容太大为止。如果内容太大,我希望将recyclerview扩展为可填充的空间,同时在顶部保留200dp。在iOS中,可以使用> = 200约束。这可能在android上吗?怎么样?

Ato*_*ean 6

啊! 我忘了在顶部添加垂直约束。将FrameLayout更改为此就可以了。

    <FrameLayout
    android:id="@+id/content"
    android:layout_width="match_parent"
    android:layout_height="0dp"
    android:layout_marginTop="200dp"
    app:layout_constraintTop_toBottomOf="@id/appBarLayout"
    app:layout_constraintBottom_toBottomOf="parent" />
Run Code Online (Sandbox Code Playgroud)