I have a fragment which can have 20+ AutoCompleteTextViews and 20+ TextInputEditTexts – all of these are wrapped within their own TextInputLayout. The top level is a NestedScrollView and all of the text fields are located within a ConstraintLayout. How can I efficiently display these without losing frames and experiencing lag? On high-end devices, it works as expected, but on low-end devices, the user experiences a brief lag while the UI renders. I’ve thought about RecyclerView but I’ve read that it’s not recommended when using any sort of EditText, especially if the entered text needs to be stored in local variables, which they do. I’ve also experimented with ViewStubs, which mainly just shifts when the lag happens.
Below is an example of how my UI is currently built. This code repeats with just the IDs, Hints and constraints changing.
<androidx.core.widget.NestedScrollView
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"
app:layout_constraintTop_toBottomOf="@+id/warningLabel"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:paddingBottom="100dp">
<androidx.constraintlayout.widget.ConstraintLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".main.TestFragment">
<com.google.android.material.textfield.TextInputLayout
android:id="@+id/genericLabel"
style="@style/Widget.MaterialComponents.TextInputLayout.OutlinedBox.ExposedDropdownMenu"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:hint="Test"
android:padding="10dp"
android:textColorHint="@color/gray"
app:boxStrokeColor="@color/lightblue"
app:cursorColor="@color/darkblue"
app:hintTextColor="@color/darkblue"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent">
<AutoCompleteTextView
android:id="@+id/generic"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:cursorVisible="false"
android:ems="10"
android:minHeight="48dp"
android:paddingStart="10dp"
android:textColor="@color/darkblue"
android:textSize="15sp"
android:textStyle="bold"
tools:ignore="SpeakableTextPresentCheck" />
</com.google.android.material.textfield.TextInputLayout>
<com.google.android.material.textfield.TextInputLayout
android:id="@+id/genericCommentsLabel"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:hint="Comments"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/genericLabel"
android:padding="10dp"
app:hintTextColor="@color/darkblue"
android:textColorHint="@color/gray"
app:boxStrokeColor="@color/lightblue"
app:cursorColor="@color/darkblue">
<com.google.android.material.textfield.TextInputEditText
android:id="@+id/genericComments"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:ems="10"
android:minHeight="48dp"
android:paddingStart="10dp"
android:textColor="@color/darkblue"
android:textSize="15sp"
android:textStyle="bold"
android:maxLength="60"
android:inputType="textCapSentences"/>
</com.google.android.material.textfield.TextInputLayout>