结合使用ScrollView Activity和AdjustPan时的空白

时间:2019-06-22 13:06:01

标签: android xml layout scrollview adjustpan

我的线性布局占用太多空间。所以我决定将其放在ScrollView中。

布局的底部有一个EditText供用户输入。为了使布局在AndroidManifest.xml中为我输入的Activity调整大小:

android:windowSoftInputMode="adjustPan"

当我只有线性布局时还可以,但是现在结合使用Scroll View,我得到了一个空格,我认为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>

Before clicking keyboard

After clicking keyboard

1 个答案:

答案 0 :(得分:1)

替换为以下代码

    <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>
相关问题