Tuesday, 7 September 2021

View doesn't scroll all the way up when clicking EditText

When I tap 1 of the 3 edittexts, my keyboard appears and the view scrolls up a little bit. But my layout should move all the way up. My xml file:

<androidx.constraintlayout.widget.ConstraintLayout
    android:layout_width="match_parent"
    android:layout_height="match_parent">

    <ScrollView
        android:id="@+id/scrollView"
        android:fillViewport="true"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        app:layout_constraintBottom_toBottomOf="parent"
        app:layout_constraintTop_toBottomOf="@+id/toolbar"
        app:layout_constraintVertical_bias="0.01999998">

        <androidx.constraintlayout.widget.ConstraintLayout
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:paddingBottom="126dp">

            <EditText
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:layout_margin="@dimen/padding_default"
                android:padding="@dimen/padding_small"
                android:paddingHorizontal="@dimen/padding_default"
                app:layout_constraintTop_toTopOf="parent"
                tools:layout_editor_absoluteX="16dp" />

            <EditText
                android:id="@+id/instructionsEditText"
                android:layout_width="match_parent"
                android:layout_height="600dp"
                android:layout_margin="@dimen/padding_default"
                android:gravity="top|start"
                android:padding="@dimen/padding_small"
                android:paddingHorizontal="@dimen/padding_default"
                app:layout_constraintTop_toBottomOf="@+id/amountPersonsEditText" />

            <EditText
                android:id="@+id/notesEditText"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:layout_margin="@dimen/padding_default"
                android:padding="@dimen/padding_small"
                android:paddingHorizontal="@dimen/padding_default"
                app:layout_constraintBottom_toBottomOf="parent"
                app:layout_constraintTop_toBottomOf="@+id/instructionsEditText"
                tools:layout_editor_absoluteX="16dp" />
        </androidx.constraintlayout.widget.ConstraintLayout>
    </ScrollView>

    <android.widget.Button
        android:id="@+id/saveInstructionsButton"
        style="@style/buttonStyle"
        android:layout_width="0dp"
        android:layout_height="wrap_content"
        android:layout_marginBottom="@dimen/padding_default"
        android:gravity="center"
        android:imeOptions="actionDone"
        android:text="@string/instructions_button_text"
        app:layout_constraintBottom_toBottomOf="parent"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintStart_toStartOf="parent" />

</androidx.constraintlayout.widget.ConstraintLayout>

My androidmanifest:

    <activity
        android:name=".ui.instructions.InstructionsActivity"
        android:windowSoftInputMode="adjustResize"
        android:screenOrientation="portrait" />

I've also tried this:

fun ScrollView.moveToTop() {
    this.isFocusableInTouchMode = true
    this.fullScroll(View.FOCUS_DOWN)
    this.smoothScrollTo(0, bottom)
}

but the button is outside the scrollview and the button bottom should be at the top of the keyboard.

Start:

enter image description here

Actual:

enter image description here

Expected:

enter image description here



from View doesn't scroll all the way up when clicking EditText

No comments:

Post a Comment