You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Android中adjustResize与ScrollView配合失效问题求助

解决Android键盘弹出覆盖EditText的问题

嘿,我之前也碰到过一模一样的情况——明明设置了adjustResize,但底部输入框还是被键盘死死挡住。结合你提供的代码来看,问题主要出在布局高度设置和系统窗口Insets的处理上,咱们一步步来修复:

1. 先检查主题配置

首先确认你的@style/AppTheme.ProfileEdit主题没有添加以下属性,这些设置会直接破坏adjustResize的生效逻辑:

<!-- 确保主题里没有这些配置 -->
<item name="android:windowFullscreen">true</item>
<item name="android:windowTranslucentNavigation">true</item>

2. 修复AppBarLayout的系统窗口适配

给AppBarLayout加上android:fitsSystemWindows="true"属性,让它正确识别系统状态栏的高度,这样adjustResize才能准确计算屏幕的可用显示区域:

<android.support.design.widget.AppBarLayout
    android:id="@+id/profile_appbar"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:background="@drawable/topbar_gradient"
    android:theme="@style/AppTheme.Dark"
    android:fitsSystemWindows="true" <!-- 添加这行 -->
    app:layout_constraintLeft_toLeftOf="parent"
    app:layout_constraintRight_toRightOf="parent"
    app:layout_constraintTop_toTopOf="parent">

3. 调整ScrollView子布局的高度

你的ScrollView内部的RelativeLayout和GridLayout都设置了android:layout_height="match_parent",这会让ScrollView误以为内容高度和自身完全一致,不需要滚动。把它们改成wrap_content,让内容自适应高度,这样ScrollView才能在键盘弹出时自动滚动到被遮挡的输入框:

修改RelativeLayout:

<RelativeLayout
    android:layout_width="match_parent"
    android:layout_height="wrap_content" <!-- 从match_parent改为wrap_content -->
    android:background="@color/bg_light">

修改GridLayout:

<GridLayout
    android:layout_width="match_parent"
    android:layout_height="wrap_content" <!-- 从match_parent改为wrap_content -->
    android:layout_below="@id/profile_pic"
    android:background="@color/white"
    android:columnCount="2"
    android:orientation="horizontal">

4. 修正EditText的高度笔误

注意到你最后一个EditTextedit_bio的高度写的是android:layout_height="wrap",这是语法错误,改成wrap_content,同时建议加上多行输入类型适配Bio场景:

<android.support.v7.widget.AppCompatEditText
    android:id="@+id/edit_bio"
    android:layout_width="match_parent"
    android:layout_height="wrap_content" <!-- 修正为wrap_content -->
    android:inputType="textMultiLine" <!-- 适配多行输入 -->
    tools:text="@tools:sample/lorem/random"/>

最后确认Manifest配置

你当前的windowSoftInputMode设置是正确的,保留即可:

android:windowSoftInputMode="stateHidden|adjustResize"

做完这些修改后重新运行App,点击底部输入框时,ScrollView应该会自动滚动,让输入框稳稳避开键盘啦!

内容的提问来源于stack exchange,提问作者MichelReap

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.05.27 10:01:23