我的线性布局占用了太多空间。所以我决定将其放入卷轴上。
布局在用户输入的底部具有递观。为了使布局在AndroidManifest.xml中进行调整大小:
:android:windowSoftInputMode="adjustPan"
当我刚刚进行线性布局时,这是可以的,但是现在结合滚动视图,我有一个空白,我认为Android正在尝试为键盘腾出空间。
layout.xml:
<ScrollView android:layout_width="match_parent"
android:layout_height="match_parent"
xmlns:android="http://schemas.android.com/apk/res/android">
<androidx.appcompat.widget.LinearLayoutCompat
android:isScrollContainer="false"
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:orientation="vertical"
tools:context=".MainActivity"
android:background="@color/colorPrimary">
...
</androidx.appcompat.widget.LinearLayoutCompat>
</ScrollView>
单击键盘之前
单击键盘
替换为以下代码
<ScrollView android:layout_width="match_parent"
android:layout_height="match_parent"
android:fillViewport="true"
xmlns:android="http://schemas.android.com/apk/res/android">
<androidx.appcompat.widget.LinearLayoutCompat
android:isScrollContainer="false"
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:orientation="vertical"
tools:context=".MainActivity"
android:background="@color/colorPrimary">
...
</androidx.appcompat.widget.LinearLayoutCompat>
</ScrollView>