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

API 34及以上layout_alignParentBottom=true不贴底随键盘移动求助

解决API 34+中RelativeLayout贴底控件随软键盘上移的问题

试试这几个办法解决:

1. 修改Activity的软键盘调整模式

在AndroidManifest.xml里对应Activity的标签下添加软键盘模式配置,让系统弹出键盘时不调整布局高度,这样贴底控件就不会跟着上移:

<activity
    android:name=".你的Activity类名"
    android:windowSoftInputMode="adjustNothing">
    <!-- 其他配置 -->
</activity>

如果担心输入框被键盘挡住,可以把输入区域放在ScrollView里,这样用户能滚动到输入框位置,同时底部控件保持贴死屏幕底部。

2. 改用ConstraintLayout替代RelativeLayout

RelativeLayout已经被官方推荐用ConstraintLayout替代,后者的约束逻辑更稳定,适配新API也更可靠:
把外层的RelativeLayout换成ConstraintLayout,然后给贴底的FrameLayout设置底部约束:

<androidx.constraintlayout.widget.ConstraintLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    android:layout_width="match_parent"
    android:layout_height="match_parent">

    <!-- 页面其他控件 -->

    <FrameLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        app:layout_constraintBottom_toBottomOf="parent"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintEnd_toEndOf="parent">
        <!-- 你的底部内容 -->
    </FrameLayout>

</androidx.constraintlayout.widget.ConstraintLayout>

这种方式下,只要保持ConstraintLayout全屏,控件会始终贴住布局底部,不受键盘弹出影响。

3. 检查fitsSystemWindows属性

确保外层RelativeLayout的android:fitsSystemWindows属性设为false,如果这个属性为true,API 34+的系统布局计算逻辑可能会改变控件的底部位置:

<RelativeLayout
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:fitsSystemWindows="false">
    <!-- 子控件 -->
</RelativeLayout>

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.06.13 11:48:16