【问题标题】:How to push button when keyboard is opened打开键盘时如何按下按钮
【发布时间】:2019-11-19 04:10:11
【问题描述】:

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

我尝试了什么:android:windowSoftInputMode="adjustResize" / adjustPan /Nothig / StateHidden.... 拳头系统窗口 = 真 填充视口 = 真 将约束更改为相对布局后的 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。放弃相对布局是不可能的,因为它里面有一些不能滚动的视图

【问题讨论】:

  • 您是想隐藏键盘以查看按钮还是只是想将按钮移到键盘上方?
  • @HayesRoach,我正在尝试将按钮移动到键盘上方。

标签: android layout keyboard


【解决方案1】:

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

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

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2015-09-13
    • 1970-01-01
    • 1970-01-01
    • 2015-10-01
    • 2020-06-19
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多