ScrollView вылезает за свои границы в ConstraintLayout

Вверху экрана находятся несколько TextView. К ним привязан ScrollView, в который динамически добавляю Constraintlayout. Однако когда элементы более не влезают на экран целиком, ScrollView почему-то растягивается и наезжает на элементы сверху, к которым привязан и не прокручивается до конца.

<TextView
    android:id="@+id/inWorkTextView"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_marginStart="28dp"
    android:fontFamily="@font/poppins_medium"
    android:text="В работе: 0"
    android:gravity="center_horizontal"
    android:visibility="invisible"
    android:textColor="#4C4B5E"
    android:textSize="16sp"
    android:textStyle="bold"
    app:layout_constraintStart_toEndOf="@+id/newTextView"
    app:layout_constraintTop_toTopOf="@+id/newTextView" />

<ImageButton
    android:id="@+id/OnOffServiceBtn"
    style="@style/Widget.AppCompat.ImageButton"
    android:layout_width="58dp"
    android:layout_height="60dp"
    android:layout_marginTop="28dp"
    android:layout_marginEnd="16dp"
    android:background="#ffffff"
    android:src="@drawable/connection_ready"
    app:layout_constraintEnd_toEndOf="parent"
    app:layout_constraintTop_toTopOf="parent" />

<ToggleButton
    android:id="@+id/toggleButton"
    style="@style/toggleButton"
    android:layout_width="50dp"
    android:layout_height="29dp"
    android:layout_gravity="right"
    android:layout_marginTop="16dp"
    android:layout_marginEnd="16dp"
    android:visibility="invisible"
    android:background="@drawable/ic_toggle_bg"
    android:onClick="onTrayBtn"
    app:layout_constraintEnd_toStartOf="@+id/OnOffServiceBtn"
    app:layout_constraintTop_toTopOf="@+id/OnOffServiceBtn" />

<ScrollView
    android:id="@+id/scroll"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:paddingBottom="10dp"
    android:layout_marginRight="10dp"
    android:layout_marginLeft="10dp"
    app:layout_constraintBottom_toBottomOf="parent"
    app:layout_constraintEnd_toEndOf="parent"
    app:layout_constraintStart_toStartOf="parent"
    app:layout_constraintTop_toBottomOf="@id/inWorkTextView">

    <ConstaraintLayout
        android:id="@+id/constraint"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_marginTop="28dp"
        android:paddingBottom="10dp"
        android:orientation="vertical"></ConstaraintLayout>
</ScrollView>

Добавление новых элементов выглядит след образом

   void addNewCard(LinearLayout layout, PushData pushData){
        final View view = getLayoutInflater().inflate(R.layout.fragment_request_work, null);
        ((TextView) (view.findViewById(R.id.dateTimeView))).setText(pushData.date + " " + pushData.time);
        ((TextView) (view.findViewById(R.id.address))).setText(pushData.area);
        (view.findViewById(R.id.address)).setTag(pushData.address);
        ((TextView) (view.findViewById(R.id.cvalView))).setText(pushData.cval);
        ((TextView) (view.findViewById(R.id.taskView))).setText(pushData.task);
        ((TextView) (view.findViewById(R.id.description))).setText(pushData.name + " " + pushData.tel);
        ((TextView) (view.findViewById(R.id.rectangleNumber))).setText(pushData.number);
        if(pushData.type.equalsIgnoreCase("autoselect"))
            view.findViewById(R.id.disagreeBtn).setVisibility(View.INVISIBLE);
        else
            view.findViewById(R.id.disagreeBtn).setVisibility(View.VISIBLE);
        (view.findViewById(R.id.agreeBtn))
                .setOnClickListener(view1 -> agreeRequestWork(view.getTag().toString(), true));
        (view.findViewById(R.id.disagreeBtn))
                .setOnClickListener(view1 -> agreeRequestWork(view.getTag().toString(),false));
        layout.addView(view);
        viewMap.put(pushData.idFromServer, view);
        view.setTag(pushData.idFromServer);
    }

Добавляю разные ConstraintLayout, к примеру

<?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:layout_width="match_parent"
    android:layout_height="match_parent"
    android:background="@drawable/customborder">

    <TextView
        android:id="@+id/rectangleNumber"
        android:layout_width="60dp"
        android:layout_height="28dp"
        android:layout_marginStart="16dp"
        android:layout_marginTop="16dp"
        android:background="@drawable/rectangle"
        android:gravity="center_vertical|center_horizontal"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintTop_toTopOf="parent" />

    <TextView
        android:id="@+id/dateTimeView"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:fontFamily="@font/montserrat"
        app:layout_constraintStart_toStartOf="@+id/rectangleNumber"
        app:layout_constraintTop_toBottomOf="@+id/rectangleNumber" />

    <TextView
        android:id="@+id/address"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:fontFamily="@font/poppins_medium"
        app:layout_constraintStart_toStartOf="@+id/dateTimeView"
        app:layout_constraintTop_toBottomOf="@+id/dateTimeView" />

    <TextView
        android:id="@+id/cvalView"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:fontFamily="@font/poppins_medium"
        app:layout_constraintStart_toStartOf="@+id/address"
        app:layout_constraintTop_toBottomOf="@+id/address" />

    <TextView
        android:id="@+id/taskView"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:fontFamily="@font/poppins_medium"
        app:layout_constraintStart_toStartOf="@+id/cvalView"
        app:layout_constraintTop_toBottomOf="@+id/cvalView" />

    <TextView
        android:id="@+id/description"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:fontFamily="@font/montserrat"
        app:layout_constraintStart_toStartOf="@+id/taskView"
        app:layout_constraintTop_toBottomOf="@+id/taskView" />

    <Button
        android:id="@+id/agreeBtn"
        android:layout_width="100dp"
        android:layout_height="30dp"
        android:layout_marginTop="8dp"
        android:background="@drawable/rectangle"
        android:backgroundTint="#00CC4F"
        android:fontFamily="@font/montserrat"
        android:text="Принять"
        android:textColor="#FFFFFF"
        app:layout_constraintStart_toStartOf="@+id/description"
        app:layout_constraintTop_toBottomOf="@+id/description" />

    <Button
        android:id="@+id/disagreeBtn"
        android:layout_width="100dp"
        android:layout_height="30dp"
        android:layout_marginLeft="16dp"
        android:backgroundTint="#F23B51"
        android:text="Отклонить"
        android:textColor="#FFFFFF"
        android:fontFamily="@font/montserrat"
        android:background="@drawable/rectangle"
        app:layout_constraintLeft_toRightOf="@+id/agreeBtn"
        app:layout_constraintTop_toTopOf="@+id/agreeBtn" />
</androidx.constraintlayout.widget.ConstraintLayout>

как сделать так, чтобы ScrollView не залезал на другие элементы и прокручивался полностью?


Ответы (0 шт):