安卓 如何仅在显示软键盘时调整滚动视图的大小



所以我有一个布局,上面有一个工具栏,上面有一个带有文本视图的滚动视图,在滚动视图下有 2 个按钮。我需要按钮在显示时位于软键盘下方,但使 ScrollView 在软键盘顶部的边缘调整大小。我已经在清单上添加了 android:windowSoftInputMode="adjustNothing" 并在滚动视图上 android:isScrollContainer="false">

问题是显示键盘时我无法在滚动视图的边缘滚动。所以我需要在显示键盘时调整它的大小 这是布局

<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@drawable/map_new_bg"
android:orientation="vertical"
android:padding="10dp">
<ScrollView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_weight="1"
android:isScrollContainer="false" >
<LinearLayout
android:id="@+id/llRegInfo"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:orientation="vertical"
android:padding="10dp">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal">
<EditText
android:id="@+id/etFirstName"
style="@style/EditText"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginLeft="10dp"
android:layout_marginRight="10dp"
android:layout_weight="1"
android:ems="10"
android:inputType="textPersonName"
android:text="" />
<EditText
android:id="@+id/etFirstName"
style="@style/EditText"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginLeft="10dp"
android:layout_marginRight="10dp"
android:layout_weight="1"
android:ems="10"
android:inputType="textPersonName"
android:text="" />
....
</LinearLayout>
<!--MoreEditTexts Inside LinearLayout Like Above-->
</LinearLayout>
</ScrollView>
<LinearLayout
android:layout_width="0dp"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:id="@+id/linearLayout7"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintLeft_toLeftOf="parent">
<Button
android:id="@+id/btnRegBack"
style="@style/RedButton"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_margin="10dp"
android:layout_weight="1"
android:text="@string/return_text" />
<Button
android:id="@+id/btnRegNext"
style="@style/RedButton"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_margin="10dp"
android:layout_weight="1"
android:text="@string/next_text"
android:textAllCaps="false" />
</LinearLayout>
</LinearLayout>

你有没有试过告诉Android当软键盘出现时该怎么做?

getWindow()
.setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_ADJUST_RESIZE);

(查看所有值,看看哪一个适合您的账单(。

最新更新