打开键盘时如何按下按钮

时间:2019-07-09 14:54:22

标签: android layout keyboard

我有RelativeLayout-> ScrollView-> ConstraintLayout-> EditText..Button-> / Constraint-> / ScrollView-> / RelativeLayout 打开键盘后,它仅按EditText,而Button隐藏在keayboard下面。

我尝试了什么:android:windowSoftInputMode =“ adjustResize” / AdjustPan / Nothig / StateHidden .... fistSystemWindow = true fillViewPort = true 更改为相对布局后的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。放下相对布局是不可能的,因为它内部有一些视图,无法滚动

1 个答案:

答案 0 :(得分:0)

我找到了一种解决方法。 在onResume中,我将侦听器添加到更改大小的侦听器的parentView中。更改parentView大小后,在其中滚动至bottm

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