ConstraintLayout, как распространить оставшееся представление - PullRequest
0 голосов
/ 20 сентября 2018

Я впервые работаю с ContraintLayouts, и мне нужна помощь

У меня есть ConstraintLayout с TextView, LinearLayout и RecyclerView, и я хочу, чтобы RecyclerViewраспространяется, чтобы заполнить его родителя, без необходимости использовать взвешенные цепочки, потому что у меня нет отношения отношения между всеми представлениями.Как я могу это сделать?

Высота TextView должна быть wrap_content Высота LinearLayout должна быть wrap_content Высота Recycler должна быть "Возьмите оставшееся пространство"

Я пыталсяиспользовать расширение цепочки, но это, похоже, не имеет никакого эффекта

<android.support.constraint.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
xmlns:tools="http://schemas.android.com/tools"
xmlns:app="http://schemas.android.com/apk/res-auto">

    <android.support.v7.widget.AppCompatTextView
        app:layout_constraintVertical_chainStyle="spread"
        android:id="@+id/close"
        android:layout_width="50dp"
        android:layout_height="20dp"
        android:layout_marginStart="16dp"
        android:layout_marginTop="36dp"
        android:textColor="@android:color/white"
        android:textSize="15sp" />


        <LinearLayout
            app:layout_constraintVertical_chainStyle="spread"
            android:layout_marginTop="50dp"
            app:layout_constraintTop_toBottomOf="@id/close"
            android:id="@+id/headline"
            android:layout_width="match_parent"
            android:layout_height="0dp"
            android:gravity="center"
            android:orientation="vertical">

            <android.support.v7.widget.AppCompatTextView
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:textColor="@android:color/white"
                android:textSize="26sp"
                app:layout_constraintVertical_chainStyle="spread" />

            <android.support.v7.widget.AppCompatTextView
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_marginTop="2dp"
                android:textColor="@android:color/white"
                android:textSize="14sp"/>

            <android.support.v7.widget.AppCompatTextView
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_marginTop="11dp"
                android:textColor="@android:color/white"
                android:textSize="32sp" />

            <android.support.v7.widget.AppCompatTextView
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_marginBottom="8dp"
                android:layout_marginTop="20dp"
                android:textColor="@android:color/white"
                android:textSize="14sp"/>

        </LinearLayout>


<android.support.v7.widget.RecyclerView
    android:layout_width="match_parent"
    android:layout_height="0dp"
    android:background="@android:color/white"
    app:layout_constraintTop_toBottomOf="@id/headline"
    app:layout_constraintVertical_chainStyle="spread" />


 </android.support.constraint.ConstraintLayout>

То, что я ищу

РЕДАКТИРОВАТЬ: мое представление Recycler только завершение, поэтому у меня есть тонпробел

[1]

Ответы [ 3 ]

0 голосов
/ 20 сентября 2018

Решение:

Итак, просто скопируйте, вставьте его и проверьте:

<?xml version="1.0" encoding="utf-8"?>
<android.support.constraint.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
app:layout_behavior="@string/appbar_scrolling_view_behavior">

<android.support.v7.widget.AppCompatTextView
    android:id="@+id/close"
    android:layout_width="0dp"
    android:layout_height="wrap_content"
    android:textColor="@android:color/white"
    android:textSize="15sp"
    app:layout_constraintEnd_toEndOf="parent"
    app:layout_constraintStart_toStartOf="parent"
    app:layout_constraintTop_toTopOf="parent"
    app:layout_constraintVertical_chainStyle="spread"/>


<LinearLayout
    android:id="@+id/headline"
    android:layout_width="match_parent"
    android:layout_height="0dp"
    android:gravity="center"
    android:orientation="vertical"
    app:layout_constraintEnd_toEndOf="parent"
    app:layout_constraintStart_toStartOf="parent"
    app:layout_constraintTop_toBottomOf="@id/close"
    app:layout_constraintVertical_chainStyle="spread">

    <android.support.v7.widget.AppCompatTextView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:textColor="@android:color/white"
        android:textSize="26sp"
        app:layout_constraintVertical_chainStyle="spread" />

    <android.support.v7.widget.AppCompatTextView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_marginTop="2dp"
        android:textColor="@android:color/white"
        android:textSize="14sp" />

    <android.support.v7.widget.AppCompatTextView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_marginTop="11dp"
        android:textColor="@android:color/white"
        android:textSize="32sp" />

    <android.support.v7.widget.AppCompatTextView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_marginBottom="8dp"
        android:layout_marginTop="20dp"
        android:textColor="@android:color/white"
        android:textSize="14sp" />

</LinearLayout>


<android.support.v7.widget.RecyclerView
    android:layout_width="match_parent"
    android:layout_height="0dp"
    android:background="@android:color/white"
    app:layout_constraintBottom_toBottomOf="parent"
    app:layout_constraintEnd_toEndOf="parent"
    app:layout_constraintStart_toStartOf="parent"
    app:layout_constraintTop_toBottomOf="@id/headline"
    app:layout_constraintVertical_chainStyle="spread" />

</android.support.constraint.ConstraintLayout>
0 голосов
/ 20 сентября 2018

Попробуйте это

<android.support.constraint.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    xmlns:tools="http://schemas.android.com/tools"
    xmlns:app="http://schemas.android.com/apk/res-auto">

    <android.support.v7.widget.AppCompatTextView
        android:id="@+id/close"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_marginStart="16dp"
        android:layout_marginTop="36dp"
        android:textColor="@android:color/white"
        android:textSize="15sp" />


    <LinearLayout
        app:layout_constraintTop_toBottomOf="@id/close"
        android:id="@+id/headline"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:gravity="center"
        android:orientation="vertical">

        <android.support.v7.widget.AppCompatTextView
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:textColor="@android:color/white"
            android:textSize="26sp"
            app:layout_constraintVertical_chainStyle="spread" />

        <android.support.v7.widget.AppCompatTextView
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_marginTop="2dp"
            android:textColor="@android:color/white"
            android:textSize="14sp"/>

        <android.support.v7.widget.AppCompatTextView
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_marginTop="11dp"
            android:textColor="@android:color/white"
            android:textSize="32sp" />

        <android.support.v7.widget.AppCompatTextView
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_marginBottom="8dp"
            android:layout_marginTop="20dp"
            android:textColor="@android:color/white"
            android:textSize="14sp"/>

    </LinearLayout>


    <android.support.v7.widget.RecyclerView
        android:layout_width="match_parent"
        android:layout_height="0dp"
        android:background="@android:color/white"
        app:layout_constraintBottom_toBottomOf="parent"
        app:layout_constraintTop_toBottomOf="@id/headline"
        app:layout_constraintVertical_chainStyle="spread" />


</android.support.constraint.ConstraintLayout>

ВЫХОД

enter image description here

0 голосов
/ 20 сентября 2018

Дайте layout_height recyclerView как 0dp, например:

layout_height = "0dp"

, а также укажите, что вы не задали нижнее ограничение:

app:layout_constraintBottom_toBottomOf="parent"
...