ConstraintLayout переносит только части содержимого - PullRequest
0 голосов
/ 09 января 2020

У меня есть ConstraintLayout, который охватывает только части содержимого, и я не понимаю, почему. Вот графическое представление моей ситуации:

Section of contents wrapped by my ConstraintLayout

View that isn't wrapped by my ConstraintLayout

Я хочу, чтобы мой mainConstraintLayout оборачивает все. Если я изменю layout_height из mainConstraintLayout с wrap_content на match_parent, я получу следующее предупреждение, и оно все еще не будет работать:

Проверка размера ScrollView : Этот androidx.constraintlayout.widget.ConstraintLayout должен использовать android: layout_height = "wrap_content". Дети ScrollView должны установить для своих атрибутов layout_width или layout_height значение wrap_content, а не fill_parent или match_parent в измерении прокрутки. Идентификатор проблемы: ScrollViewSize

Кто-нибудь может мне помочь? Заранее спасибо.

Обновление: xml

<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.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:id="@+id/mainView"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:background="@android:color/white"
    android:backgroundTint="@android:color/white"
    tools:context=".activities.EventActivity">

    <ScrollView
        android:id="@+id/scrollView"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        app:layout_constraintBottom_toBottomOf="parent"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintTop_toTopOf="parent">

        <androidx.constraintlayout.widget.ConstraintLayout
            android:id="@+id/mainConstraintLayout"
            android:layout_width="match_parent"
            android:layout_height="match_parent">

            <ImageView
                android:id="@+id/eventMainPicture"
                android:layout_width="0dp"
                android:layout_height="200dp"
                android:layout_marginBottom="10dp"
                android:contentDescription="@string/event_image_content_description"
                android:scaleType="fitXY"
                app:layout_constraintBottom_toTopOf="@+id/eventHeaderWrapper"
                app:layout_constraintEnd_toEndOf="parent"
                app:layout_constraintStart_toStartOf="parent"
                app:layout_constraintTop_toTopOf="parent"
                app:srcCompat="@drawable/event_placeholder_image" />

            <androidx.constraintlayout.widget.ConstraintLayout
                android:id="@+id/eventActionWrapper"
                android:layout_width="match_parent"
                android:layout_height="50dp"
                android:layout_marginStart="15dp"
                android:layout_marginTop="10dp"
                android:layout_marginEnd="15dp"
                app:layout_constraintEnd_toEndOf="parent"
                app:layout_constraintStart_toStartOf="parent"
                app:layout_constraintTop_toBottomOf="@+id/eventHeaderWrapper">

                <Button
                    android:id="@+id/willPartecipateButton"
                    style="@android:style/Widget.Material.Button.Inset"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:backgroundTint="@color/primaryBlue"
                    android:paddingLeft="15dp"
                    android:paddingRight="15dp"
                    android:text="@string/event_will_partecipate"
                    android:textColor="@color/primaryOrange"
                    android:textColorHighlight="@color/primaryOrange"
                    android:textColorHint="@color/primaryOrange"
                    android:textColorLink="@color/primaryOrange"
                    android:textSize="14sp"
                    app:layout_constraintEnd_toStartOf="@+id/interestedButton"
                    app:layout_constraintHorizontal_bias="0.5"
                    app:layout_constraintStart_toStartOf="parent"
                    app:layout_constraintTop_toTopOf="parent" />

                <Button
                    android:id="@+id/interestedButton"
                    style="@android:style/Widget.Material.Button.Inset"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:backgroundTint="@color/primaryOrange"
                    android:paddingLeft="15dp"
                    android:paddingRight="15dp"
                    android:text="@string/event_interested"
                    android:textColor="@color/primaryBlue"
                    android:textColorHighlight="@color/primaryOrange"
                    android:textColorHint="@color/primaryBlue"
                    android:textColorLink="@color/primaryBlue"
                    android:textSize="14sp"
                    app:layout_constraintEnd_toEndOf="parent"
                    app:layout_constraintHorizontal_bias="0.5"
                    app:layout_constraintStart_toEndOf="@+id/willPartecipateButton"
                    app:layout_constraintTop_toTopOf="parent" />

            </androidx.constraintlayout.widget.ConstraintLayout>

            <androidx.constraintlayout.widget.ConstraintLayout
                android:id="@+id/eventHeaderWrapper"
                android:layout_width="match_parent"
                android:layout_height="match_parent"
                android:layout_marginStart="15dp"
                android:layout_marginTop="10dp"
                android:layout_marginEnd="15dp"
                app:layout_constraintEnd_toEndOf="parent"
                app:layout_constraintStart_toStartOf="parent"
                app:layout_constraintTop_toBottomOf="@+id/eventMainPicture">

                <TextView
                    android:id="@+id/eventCreatedBy"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:layout_marginTop="5dp"
                    android:text="@string/event_createad_by"
                    android:textSize="18sp"
                    app:layout_constraintStart_toStartOf="parent"
                    app:layout_constraintTop_toBottomOf="@+id/eventNamePlaceholder" />

                <TextView
                    android:id="@+id/eventCreatorName"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:layout_marginStart="5dp"
                    android:layout_marginTop="5dp"
                    android:text="@string/event_creator_placeholder"
                    android:textSize="18sp"
                    android:textStyle="bold"
                    app:layout_constraintStart_toEndOf="@+id/eventCreatedBy"
                    app:layout_constraintTop_toBottomOf="@+id/eventNamePlaceholder" />

                <TextView
                    android:id="@+id/eventNamePlaceholder"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:text="@string/event_name_placeholder"
                    android:textColor="@android:color/black"
                    android:textColorHighlight="@android:color/black"
                    android:textColorHint="@android:color/black"
                    android:textColorLink="@android:color/black"
                    android:textSize="28sp"
                    android:textStyle="bold"
                    app:layout_constraintStart_toStartOf="parent"
                    app:layout_constraintTop_toTopOf="parent" />
            </androidx.constraintlayout.widget.ConstraintLayout>

            <androidx.constraintlayout.widget.ConstraintLayout
                android:id="@+id/eventInfoWrapper"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:layout_marginStart="15dp"
                android:layout_marginTop="10dp"
                android:layout_marginEnd="15dp"
                app:layout_constraintEnd_toEndOf="parent"
                app:layout_constraintStart_toStartOf="parent"
                app:layout_constraintTop_toBottomOf="@+id/eventActionWrapper">

                <ImageView
                    android:id="@+id/eventDateIcon"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    app:layout_constraintStart_toStartOf="parent"
                    app:layout_constraintTop_toTopOf="parent"
                    app:srcCompat="@drawable/calendar_icon" />

                <ImageView
                    android:id="@+id/eventPositionIcon"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:layout_marginTop="10dp"
                    android:layout_marginBottom="5dp"
                    app:layout_constraintBottom_toBottomOf="parent"
                    app:layout_constraintStart_toStartOf="parent"
                    app:layout_constraintTop_toBottomOf="@+id/eventDateIcon"
                    app:srcCompat="@drawable/position_icon" />

                <TextView
                    android:id="@+id/eventDate"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:layout_marginStart="6dp"
                    android:text="@string/event_date"
                    android:textSize="16sp"
                    app:layout_constraintBottom_toBottomOf="@+id/eventDateIcon"
                    app:layout_constraintStart_toEndOf="@+id/eventDateIcon"
                    app:layout_constraintTop_toTopOf="parent" />

                <TextView
                    android:id="@+id/eventPosition"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:layout_marginStart="6dp"
                    android:layout_marginTop="10dp"
                    android:text="@string/event_place"
                    android:textSize="16sp"
                    app:layout_constraintBottom_toBottomOf="@+id/eventPositionIcon"
                    app:layout_constraintStart_toEndOf="@+id/eventPositionIcon"
                    app:layout_constraintTop_toBottomOf="@+id/eventDate" />

            </androidx.constraintlayout.widget.ConstraintLayout>

            <androidx.constraintlayout.widget.ConstraintLayout
                android:id="@+id/eventDescriptionWrapper"
                android:layout_width="match_parent"
                android:layout_height="match_parent"
                android:layout_marginStart="15dp"
                android:layout_marginTop="15dp"
                android:layout_marginEnd="15dp"
                app:layout_constraintEnd_toEndOf="parent"
                app:layout_constraintStart_toStartOf="parent"
                app:layout_constraintTop_toBottomOf="@+id/eventInfoWrapper">


                <TextView
                    android:id="@+id/eventDescriptionTitle"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:text="@string/event_description_title"
                    android:textColor="@android:color/black"
                    android:textColorHighlight="@android:color/black"
                    android:textColorHint="@android:color/black"
                    android:textColorLink="@android:color/black"
                    android:textSize="20sp"
                    android:textStyle="bold"
                    app:layout_constraintStart_toStartOf="parent"
                    app:layout_constraintTop_toTopOf="parent" />

                <TextView
                    android:id="@+id/eventDescription"
                    android:layout_width="0dp"
                    android:layout_height="wrap_content"
                    android:layout_marginTop="10dp"
                    android:text="@string/event_description"
                    app:layout_constraintStart_toStartOf="parent"
                    app:layout_constraintTop_toBottomOf="@+id/eventDescriptionTitle" />

            </androidx.constraintlayout.widget.ConstraintLayout>

            <androidx.constraintlayout.widget.ConstraintLayout
                android:id="@+id/participantsWrapper"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_marginStart="15dp"
                android:layout_marginTop="20dp"
                app:layout_constraintStart_toStartOf="parent"
                app:layout_constraintTop_toBottomOf="parent">

                <TextView
                    android:id="@+id/participantsT"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:text="@string/event_participants"
                    android:textColor="@android:color/black"
                    android:textColorHighlight="@android:color/black"
                    android:textColorHint="@android:color/black"
                    android:textColorLink="@android:color/black"
                    android:textSize="20sp"
                    android:textStyle="bold"
                    app:layout_constraintStart_toStartOf="parent"
                    app:layout_constraintTop_toTopOf="parent" />
            </androidx.constraintlayout.widget.ConstraintLayout>

        </androidx.constraintlayout.widget.ConstraintLayout>
    </ScrollView>

    <com.github.ybq.android.spinkit.SpinKitView
        android:id="@+id/loadingView"
        style="@style/SpinKitView.Large.CubeGrid"
        android:layout_width="74dp"
        android:layout_height="wrap_content"
        android:layout_gravity="center"
        android:visibility="invisible"
        app:SpinKit_Color="@color/primaryOrange"
        app:layout_constraintBottom_toBottomOf="@+id/scrollView"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintStart_toStartOf="@+id/scrollView"
        app:layout_constraintTop_toTopOf="@+id/scrollView" />

</androidx.constraintlayout.widget.ConstraintLayout>

Ответы [ 2 ]

1 голос
/ 09 января 2020

Вы неправильно установили constraint на participantsWrapper Просмотр. Вы устанавливаете вершину participantsWrapper в нижней части mainConstraintLayout. Итак, естественно, это выходит за рамки mainConstraintLayout. Попробуйте

Использовать

app:layout_constraintTop_toBottomOf="@+id/eventDescriptionWrapper"

Вместо

app:layout_constraintTop_toBottomOf="parent"
0 голосов
/ 09 января 2020

Вам не нужно изменять высоту макета, чтобы включить все, вы просто должны убедиться, что все представления являются прямыми потомками макета ограничения. По сути, поместите все нужные вам представления в теги: <androidx.constraintlayout.widget.ConstraintLayout> ...</androidx.constraintlayout.widget.ConstraintLayout>

Возможно, вы захотите также сгладить этот макет. Сделайте Scrollview родительским макетом и сделайте его равным match_parent, а затем поместите все в один макет ограничения и сделайте его высоту равной wrap_content, чтобы вы не испортили прокрутку.

Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...