【问题标题】:Blank space when using ScrollView Activity in combination with adjustPan结合使用 ScrollView Activity 和 adjustPan 时的空白
【发布时间】:2019-07-01 14:33:53
【问题描述】:

我的线性布局占用了太多空间。所以我决定把它放在一个 ScrollView 里面。

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

android:windowSoftInputMode="adjustPan"

当我刚刚有一个线性布局时还可以,但现在结合滚动视图我得到一个空白空间,我认为 Android 正在尝试为键盘腾出空间。

布局.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

【问题讨论】:

  • 在你的 ScrollView 中使用 android:fillViewport="true"
  • @MilanPansuriya 哇,谢谢它的工作!如果您想提交答案,我会将其标记为正确。
  • 我已经添加了我的答案

标签: android xml layout scrollview adjustpan


【解决方案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>

【讨论】:

  • 就像任何阅读者的旁注:我不确定 android:isScrollContainer="false" 是否必要。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2015-08-02
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多