键盘打开时如何按下按钮

How to push button when keyboard is opened

我有 RelativeLayout -> ScrollView -> ConstraintLayout -> EditText..Button -> /Constraint -> /ScrollView -> /RelativeLayout 当键盘打开时,它仅推送 EditText,但 Button 隐藏在键盘下方。

我试过的:android:windowSoftInputMode="adjustResize"/adjustPan/Nothig/StateHidden.... fistSystemWindow = 真 fillViewPort = 真 将 Constraint 更改为 Relative 布局后的 alignParentBottom NestedScrollView 而不是 ScrollView

没有任何效果。我测试 Android 6.

<RelativeLayout 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="@color/white"
    tools:context=".screens.news.leave.NewsDetailActivity">

    <include
        android:id="@+id/toolbar"
        layout="@layout/toolbar" />

    <androidx.core.widget.NestedScrollView
        android:id="@+id/scrollView"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:layout_below="@id/toolbar"
        android:paddingTop="@dimen/margin_large">

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

........
           <EditText
                android:id="@+id/commentET"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:layout_above="@id/sendComment"
                android:layout_marginStart="@dimen/margin_medium"
                android:layout_marginTop="@dimen/margin_medium"
                android:layout_marginEnd="@dimen/margin_medium"
                android:fontFamily="@font/roboto_regular"
                android:hint="Оставить комментарий"
                android:textColor="#878787"
                android:textSize="@dimen/textsize_large"
                app:layout_constraintEnd_toEndOf="parent"
                app:layout_constraintStart_toStartOf="parent"
                app:layout_constraintTop_toBottomOf="@id/commentsRV" />

            <Button
                android:id="@+id/sendComment"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:layout_marginStart="@dimen/margin_medium"
                android:layout_marginEnd="@dimen/margin_medium"
                android:layout_marginBottom="16dp"
                android:background="@drawable/button_selector"
                android:text="Оставить комментарий"
                android:textColor="@color/textWhite"
                android:visibility="visible"
                app:layout_constraintBottom_toBottomOf="parent"
                app:layout_constraintEnd_toEndOf="parent"
                app:layout_constraintStart_toStartOf="parent"
                app:layout_constraintTop_toBottomOf="@id/commentET" />
...
   </androidx.constraintlayout.widget.ConstraintLayout>
    </androidx.core.widget.NestedScrollView>
</RelativeLayout>

如何在键盘上按下按钮? PS。放弃相对布局是不可能的,因为它里面有一些视图,不能滚动

我找到了一种解决方法。 在 onResume 中,我将监听器添加到 parentView 更改大小监听器。在其中,当 parentView 大小更改时,我向下滚动到 bottm

newsLeaveParentView.addOnLayoutChangeListener { v, left, top, right, bottom, oldLeft, oldTop, oldRight, oldBottom ->
            if (bottom < oldBottom){
                scrollView.fullScroll(ScrollView.FOCUS_DOWN);
            }
        }