阻止键盘将对齐底部视图推向下方

4

我有一个层级结构如下的ConstraintLayout:

<android.support.constraint.ConstraintLayout
   android:layout_width="match_parent"
   android:layout_height="match_parent">

   <EditText
           app:layout_constraintStart_toStartOf="parent"
           app:layout_constraintEnd_toEndOf="parent"
           app:layout_constraintTop_toBottomOf="parent"/>

   <RecyclerView
           android:layout_width="0dp"
           android:layout_height="0dp"
           app:layout_constraintStart_toStartOf="parent"
           app:layout_constraintEnd_toEndOf="parent"
           app:layout_constraintBottom_toTopOf="Button"
           app:layout_constraintTop_toBottomOf="EditText"/>

   <Button
           app:layout_constraintBottom_toBottomOf="parent"
           app:layout_constraintEnd_toEndOf="parent"
           app:layout_constraintStart_toStartOf="parent"/>

</ConstraintLayout>

EditText获得焦点时,键盘将弹出并推动Button(因此也推动了RecyclerView)。我不希望发生这种情况,让键盘自由地弹出而不推动任何视图。
我尝试了很多android:windowSoftInputMode组合(以下是示例),但都没有成功。还有ScrollView的“hack”,但也没有成功。
<activity
    android:name=".Activity"
    android:screenOrientation="portrait"
    android:windowSoftInputMode="adjustPan"/>

我该如何实现这个呢?

附言:我能想到的唯一解决方案就是在键盘弹出时隐藏按钮


使用adjustPan,这样屏幕就不会被调整大小,整个屏幕只是向上移动。或者使用none,这样键盘就会出现在您的视图顶部-但在这种情况下,您可能无法看到用户正在输入什么,因为它可能被覆盖。当键盘出现时隐藏按钮是不可能的,因为没有可靠的方法来检测它。有一些技巧,但这些技巧并不总是正确的。 - Gabe Sechan
1
使用 adjustPan 或 adjustNothing 都不起作用,按钮被推上去了。 - GuilhE
如果调整了什么也没有发生,那么你可能在错误的位置使用它了。Pan会将按钮向上移动,但它将使整个屏幕向上移动-相对定位将保持不变。 - Gabe Sechan
<activity android:name=".Activity" android:screenOrientation="portrait" android:windowSoftInputMode="adjustPan"/> - GuilhE
@GuilhE 你好,我遇到了完全相同的问题。你有没有想过使用constraintLayout来解决键盘弹出而不移动其他内容的问题? - iBEK
很遗憾,我不行。我必须重新设计布局。你可以监听键盘更改并在按钮可见时隐藏它,但这很笨重。 - GuilhE
2个回答

3

尝试使用adjustNothing代替adjustPan

<activity
     ...
     android:windowSoftInputMode="adjustNothing"> 
</activity>

2

执行这个操作

<activity
   ...
   android:windowSoftInputMode="adjustPan"> 
</activity>

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接