У меня есть 2 фрагмента, каждый с ScrollView, и 1 ConstraintLayout внутри. ContraintLayout содержит несколько дочерних элементов, но ScrollViews имеет только 1 дочерний элемент. Когда я go к фрагменту 1, я не получаю ошибки. Я go к фрагменту 2, все хорошо. Однако, когда я возвращаюсь к фрагменту 1, я получаю следующую ошибку:
2020-03-20 22:56:20.491 7887-7887/? E/AndroidRuntime: FATAL EXCEPTION: main
Process: com.starenkysoftware.vanshapp, PID: 7887
java.lang.IllegalStateException: ScrollView can host only one direct child
at android.widget.ScrollView.addView(ScrollView.java:266)
at com.google.android.material.snackbar.BaseTransientBottomBar.showView(BaseTransientBottomBar.java:719)
at com.google.android.material.snackbar.BaseTransientBottomBar$1.handleMessage(BaseTransientBottomBar.java:243)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:193)
at android.app.ActivityThread.main(ActivityThread.java:6898)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:537)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:858)
Я не понимаю, как это возможно, поскольку я не добавляю ничего в макет при переключении
РЕДАКТИРОВАТЬ: Добавлен код
Фрагмент 1:
<?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">
<ScrollView
android:layout_width="match_parent"
android:layout_height="match_parent">
<androidx.constraintlayout.widget.ConstraintLayout
android:layout_width="match_parent"
android:layout_height="match_parent">
<TextView
android:id="@+id/recipient_header"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Beneficiary"
android:textStyle="bold"
android:textSize="15sp"
android:textColor="@color/colorPrimary"
android:layout_marginTop="20dp"
android:layout_marginLeft="18dp"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintLeft_toLeftOf="parent"/>
<View
android:id="@+id/recipient_splitter"
android:layout_width="match_parent"
android:layout_height="2dp"
android:layout_marginTop="3dp"
android:layout_marginLeft="18dp"
android:layout_marginRight="18dp"
android:background="@color/colorPrimary"
app:layout_constraintTop_toBottomOf="@id/recipient_header"/>
<!-- Recipient Name Fields -->
<com.google.android.material.textfield.TextInputLayout
android:id="@+id/recipient_first_name"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginTop="30dp"
android:layout_marginLeft="20dp"
app:layout_constraintHorizontal_chainStyle="spread"
android:layout_marginRight="10dp"
app:layout_constraintTop_toBottomOf="@id/recipient_splitter"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toLeftOf="@id/recipient_middle_name"
android:hint="First Name">
<com.google.android.material.textfield.TextInputEditText
android:id="@+id/first_name_field"
android:inputType="textPersonName"
android:layout_width="match_parent"
android:layout_height="wrap_content"/>
</com.google.android.material.textfield.TextInputLayout>
<com.google.android.material.textfield.TextInputLayout
android:id="@+id/recipient_middle_name"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginTop="30dp"
app:layout_constraintHorizontal_chainStyle="spread"
app:layout_constraintTop_toBottomOf="@id/recipient_splitter"
app:layout_constraintLeft_toRightOf="@id/recipient_first_name"
app:layout_constraintRight_toLeftOf="@id/recipient_last_name"
android:hint="Middle Name">
<com.google.android.material.textfield.TextInputEditText
android:id="@+id/middle_name_field"
android:inputType="textPersonName"
android:layout_width="match_parent"
android:layout_height="wrap_content"/>
</com.google.android.material.textfield.TextInputLayout>
<com.google.android.material.textfield.TextInputLayout
android:id="@+id/recipient_last_name"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginLeft="10dp"
android:layout_marginRight="20dp"
app:layout_constraintHorizontal_chainStyle="spread"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintTop_toTopOf="@+id/recipient_first_name"
app:layout_constraintBottom_toBottomOf="@+id/recipient_first_name"
app:layout_constraintLeft_toRightOf="@id/recipient_middle_name"
android:hint="Last Name">
<com.google.android.material.textfield.TextInputEditText
android:id="@+id/last_name_field"
android:inputType="textPersonName"
android:layout_width="match_parent"
android:layout_height="wrap_content"/>
</com.google.android.material.textfield.TextInputLayout>
<!-- Recipient Location Field -->
<com.google.android.material.textfield.TextInputLayout
android:id="@+id/recipient_state"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginTop="30dp"
android:layout_marginLeft="20dp"
app:layout_constraintHorizontal_chainStyle="spread"
android:layout_marginRight="10dp"
app:layout_constraintTop_toBottomOf="@id/recipient_first_name"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toLeftOf="@id/recipient_city"
android:hint="Province">
<com.google.android.material.textfield.TextInputEditText
android:id="@+id/state_field"
android:inputType="textPersonName"
android:layout_width="match_parent"
android:layout_height="wrap_content"/>
</com.google.android.material.textfield.TextInputLayout>
<com.google.android.material.textfield.TextInputLayout
android:id="@+id/recipient_city"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginLeft="10dp"
android:layout_marginRight="20dp"
app:layout_constraintHorizontal_chainStyle="spread"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintTop_toTopOf="@+id/recipient_state"
app:layout_constraintBottom_toBottomOf="@+id/recipient_state"
app:layout_constraintLeft_toRightOf="@id/recipient_state"
android:hint="City">
<com.google.android.material.textfield.TextInputEditText
android:id="@+id/city_field"
android:inputType="textPersonName"
android:layout_width="match_parent"
android:layout_height="wrap_content"/>
</com.google.android.material.textfield.TextInputLayout>
<!-- Phone Number -->
<com.google.android.material.textfield.TextInputLayout
android:id="@+id/phone_number_layout"
app:prefixText=""
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="30dp"
android:layout_marginLeft="20dp"
android:layout_marginRight="20dp"
app:layout_constraintTop_toBottomOf="@id/recipient_state"
android:hint="Phone Number">
<com.google.android.material.textfield.TextInputEditText
android:id="@+id/phone_number_field"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:inputType="phone"/>
</com.google.android.material.textfield.TextInputLayout>
<!-- Transger Info Section -->
<TextView
android:id="@+id/transfer_info_header"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Transfer Info"
android:textStyle="bold"
android:textSize="15sp"
android:textColor="@color/colorPrimary"
android:layout_marginTop="25dp"
android:layout_marginLeft="18dp"
app:layout_constraintTop_toBottomOf="@id/phone_number_layout"
app:layout_constraintLeft_toLeftOf="parent"/>
<View
android:id="@+id/transfer_info_splitter"
android:layout_width="match_parent"
android:layout_height="2dp"
android:layout_marginTop="3dp"
android:layout_marginLeft="18dp"
android:layout_marginRight="18dp"
android:background="@color/colorPrimary"
app:layout_constraintTop_toBottomOf="@id/transfer_info_header"/>
<!-- SOF (Source of Fund -->
<com.google.android.material.textfield.TextInputLayout
android:id="@+id/sof_layout"
app:prefixText=""
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="30dp"
android:layout_marginLeft="20dp"
android:layout_marginRight="20dp"
app:layout_constraintTop_toBottomOf="@id/transfer_info_splitter"
android:hint="Source of Fund">
<com.google.android.material.textfield.TextInputEditText
android:id="@+id/sof_field"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:inputType="text"/>
</com.google.android.material.textfield.TextInputLayout>
<!-- Type of Transfer Dropdown -->
<com.google.android.material.textfield.TextInputLayout
style="@style/Widget.MaterialComponents.TextInputLayout.FilledBox.ExposedDropdownMenu"
android:id="@+id/type_of_transfer_layout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="30dp"
android:layout_marginLeft="20dp"
android:layout_marginRight="20dp"
android:hint="Type"
app:layout_constraintTop_toBottomOf="@id/sof_layout">
<AutoCompleteTextView
android:id="@+id/type_of_transfer_dropdown"
android:editable="false"
android:layout_width="match_parent"
android:layout_height="wrap_content"/>
</com.google.android.material.textfield.TextInputLayout>
<androidx.constraintlayout.widget.ConstraintLayout
android:id="@+id/btb_info"
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:layout_constraintTop_toBottomOf="@id/type_of_transfer_layout">
<!-- Bank Name -->
<com.google.android.material.textfield.TextInputLayout
android:id="@+id/bank_name_layout"
app:prefixText=""
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="30dp"
android:layout_marginLeft="20dp"
android:layout_marginRight="20dp"
app:layout_constraintTop_toTopOf="parent"
android:hint="Bank Name">
<com.google.android.material.textfield.TextInputEditText
android:id="@+id/bank_name_field"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:inputType="text"/>
</com.google.android.material.textfield.TextInputLayout>
<!-- Phone Number -->
<com.google.android.material.textfield.TextInputLayout
android:id="@+id/bank_account_number_layout"
app:prefixText=""
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="30dp"
android:layout_marginLeft="20dp"
android:layout_marginRight="20dp"
app:layout_constraintTop_toBottomOf="@id/bank_name_layout"
android:hint="Bank Account Number">
<com.google.android.material.textfield.TextInputEditText
android:id="@+id/bank_account_number_field"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:inputType="number"/>
</com.google.android.material.textfield.TextInputLayout>
</androidx.constraintlayout.widget.ConstraintLayout>
<!-- Currency Selector -->
<com.google.android.material.textfield.TextInputLayout
style="@style/Widget.MaterialComponents.TextInputLayout.FilledBox.ExposedDropdownMenu"
android:id="@+id/currency_selector_layout"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="20dp"
android:layout_marginRight="20dp"
app:layout_constraintBottom_toBottomOf="@id/amount_layout"
app:layout_constraintTop_toTopOf="@id/amount_layout"
app:layout_constraintLeft_toLeftOf="parent">
<AutoCompleteTextView
android:id="@+id/currency_dropdown"
android:editable="false"
android:layout_width="match_parent"
android:layout_height="wrap_content"/>
</com.google.android.material.textfield.TextInputLayout>
<!-- Amount Field -->
<com.google.android.material.textfield.TextInputLayout
android:id="@+id/amount_layout"
app:prefixText=""
app:suffixText="CAD"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_marginTop="30dp"
android:layout_marginLeft="35dp"
android:layout_marginRight="20dp"
app:layout_constraintTop_toBottomOf="@id/btb_info"
app:layout_constraintLeft_toRightOf="@id/currency_selector_layout"
android:hint="Amount">
<com.google.android.material.textfield.TextInputEditText
android:id="@+id/amount_field"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:inputType="numberDecimal" />
</com.google.android.material.textfield.TextInputLayout>
<TextView
android:id="@+id/currency_rate_small"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="2dp"
android:text=""
android:textSize="13sp"
app:layout_constraintBottom_toTopOf="@+id/photo_checkbox"
app:layout_constraintLeft_toLeftOf="@+id/amount_layout"
app:layout_constraintTop_toBottomOf="@id/amount_layout" />
<com.google.android.material.button.MaterialButton
android:id="@+id/submit_button"
style="@style/Widget.MaterialComponents.Button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="20dp"
android:layout_marginRight="20dp"
android:text="Send"
app:layout_constraintTop_toBottomOf="@+id/amount_layout"
app:layout_constraintRight_toRightOf="parent"/>
<com.google.android.material.button.MaterialButton
android:id="@+id/photo_button"
style="@style/Widget.MaterialComponents.Button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="20dp"
android:layout_marginLeft="20dp"
android:text="Photo Verification"
app:layout_constraintTop_toBottomOf="@+id/amount_layout"
app:layout_constraintLeft_toLeftOf="parent"/>
<CheckBox
android:id="@+id/photo_checkbox"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="5dp"
android:clickable="false"
app:layout_constraintBottom_toBottomOf="@id/photo_button"
app:layout_constraintLeft_toRightOf="@id/photo_button"
app:layout_constraintTop_toTopOf="@+id/photo_button"/>
<View
android:layout_width="match_parent"
android:layout_height="30dp"
app:layout_constraintTop_toBottomOf="@id/submit_button"/>
</androidx.constraintlayout.widget.ConstraintLayout>
</ScrollView>
</androidx.constraintlayout.widget.ConstraintLayout>
Фрагмент 2:
<?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"
android:layout_width="match_parent"
android:layout_height="match_parent">
<ScrollView
android:layout_width="match_parent"
android:layout_height="match_parent">
<androidx.constraintlayout.widget.ConstraintLayout
android:layout_width="match_parent"
android:layout_height="match_parent">
<TextView
android:id="@+id/previous_transfer_title"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginStart="8dp"
android:layout_marginTop="8dp"
android:layout_marginEnd="8dp"
android:text="Previous 5 Transfers"
android:gravity="center"
android:textSize="20sp"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
<com.google.android.material.card.MaterialCardView
android:id="@+id/materialCardView1"
style="@style/Widget.MaterialComponents.CardView"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginLeft="@dimen/mtrl_card_spacing"
android:layout_marginRight="@dimen/mtrl_card_spacing"
android:layout_marginTop="15dp"
android:minHeight="100dp"
app:cardBackgroundColor="#ffffff"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@id/previous_transfer_title">
<TextView
android:id="@+id/transfer_card_1_text"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="10dp"
android:layout_marginTop="3dp"
android:text="Exchange Rate"
android:textColor="#878787"
android:textSize="20dp" />
<View
android:layout_width="match_parent"
android:layout_height="2dp"
android:layout_gravity="bottom"
android:background="@color/colorPrimary" />
</com.google.android.material.card.MaterialCardView>
<com.google.android.material.card.MaterialCardView
android:id="@+id/materialCardView2"
style="@style/Widget.MaterialComponents.CardView"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginLeft="@dimen/mtrl_card_spacing"
android:layout_marginRight="@dimen/mtrl_card_spacing"
android:layout_marginTop="20dp"
android:minHeight="100dp"
app:cardBackgroundColor="#ffffff"
app:layout_constraintTop_toBottomOf="@+id/materialCardView1">
<TextView
android:id="@+id/transfer_card_2_text"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="10dp"
android:layout_marginTop="3dp"
android:text="Exchange Rate"
android:textColor="#878787"
android:textSize="20dp" />
<View
android:layout_width="match_parent"
android:layout_height="2dp"
android:layout_gravity="bottom"
android:background="@color/colorPrimary" />
</com.google.android.material.card.MaterialCardView>
<com.google.android.material.card.MaterialCardView
android:id="@+id/materialCardView3"
style="@style/Widget.MaterialComponents.CardView"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginLeft="@dimen/mtrl_card_spacing"
android:layout_marginRight="@dimen/mtrl_card_spacing"
android:layout_marginTop="20dp"
android:minHeight="100dp"
app:cardBackgroundColor="#ffffff"
app:layout_constraintTop_toBottomOf="@+id/materialCardView2">
<TextView
android:id="@+id/transfer_card_3_text"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="10dp"
android:layout_marginTop="3dp"
android:text="Exchange Rate"
android:textColor="#878787"
android:textSize="20dp" />
<View
android:layout_width="match_parent"
android:layout_height="2dp"
android:layout_gravity="bottom"
android:background="@color/colorPrimary" />
</com.google.android.material.card.MaterialCardView>
<com.google.android.material.card.MaterialCardView
android:id="@+id/materialCardView4"
style="@style/Widget.MaterialComponents.CardView"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginLeft="@dimen/mtrl_card_spacing"
android:layout_marginRight="@dimen/mtrl_card_spacing"
android:layout_marginTop="20dp"
android:minHeight="100dp"
app:cardBackgroundColor="#ffffff"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/materialCardView3">
<TextView
android:id="@+id/transfer_card_4_text"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="10dp"
android:layout_marginTop="3dp"
android:text="Exchange Rate"
android:textColor="#878787"
android:textSize="20dp" />
<View
android:layout_width="match_parent"
android:layout_height="2dp"
android:layout_gravity="bottom"
android:background="@color/colorPrimary" />
</com.google.android.material.card.MaterialCardView>
<com.google.android.material.card.MaterialCardView
android:id="@+id/materialCardView5"
style="@style/Widget.MaterialComponents.CardView"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginLeft="@dimen/mtrl_card_spacing"
android:layout_marginRight="@dimen/mtrl_card_spacing"
android:layout_marginTop="20dp"
android:layout_marginBottom="15dp"
android:minHeight="100dp"
app:cardBackgroundColor="#ffffff"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/materialCardView4"
app:layout_constraintBottom_toBottomOf="parent">
<TextView
android:id="@+id/transfer_card_5_text"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="10dp"
android:layout_marginTop="3dp"
android:text="Exchange Rate"
android:textColor="#878787"
android:textSize="20dp" />
<View
android:layout_width="match_parent"
android:layout_height="2dp"
android:layout_gravity="bottom"
android:background="@color/colorPrimary" />
</com.google.android.material.card.MaterialCardView>
</androidx.constraintlayout.widget.ConstraintLayout>
</ScrollView>
</androidx.constraintlayout.widget.ConstraintLayout>