【发布时间】:2019-05-18 16:56:31
【问题描述】:
我有带有 ScorllView 和 Button 的 ConstraintLayout(附加到屏幕底部。当我在 ScrollView 中编辑 EditText 输入时。然后出现的键盘正在向上移动我的 ScrollView 内容(所需的行为,所以我可以滚动到末尾它),但它也按下按钮(不良行为)。
我想我可以改变windowAdjustMode,也许我可以检测到键盘显示然后隐藏这个按钮?但这两种解决方案并不完美。
XML:
<?xml version="1.0" encoding="utf-8"?>
<android.support.constraint.ConstraintLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent">
<ScrollView
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintBottom_toTopOf="@id/submitButton"
android:layout_width="0dp"
android:layout_height="0dp"
android:layout_margin="0dp">
<android.support.constraint.ConstraintLayout
android:layout_width="match_parent"
android:layout_height="match_parent">
<EditText /> goes here
</android.support.constraint.ConstraintLayout>
</ScrollView>
<Button
android:id="@+id/submitButton"
android:layout_width="0dp"
android:layout_height="50dp"
android:layout_margin="0dp"
android:text="@string/wizard_singup_step_submit_button"
style="@style/FormSubmitButton"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintBottom_toBottomOf="parent" />
</android.support.constraint.ConstraintLayout>
【问题讨论】:
-
只需在清单文件中的
activity标签中使用android:windowSoftInputMode="adjustNothing"即可 -
但是如果我改变它就可以滚动到 ScrollView 的末尾?我当然会马上试试。
-
用问题分享你的 xml 布局
-
我添加了xml示例
标签: android keyboard window-soft-input-mode