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

Android聊天应用:键盘弹出时避免LinearLayout溢出问题求助

聊天应用键盘弹出时LinearLayout溢出布局问题

我正在开发一款聊天应用,目前功能运行正常,但遇到了键盘弹出时的布局问题。

未弹出键盘时的界面状态:
未弹出键盘的聊天界面

点击输入框弹出键盘后的界面状态:
弹出键盘后的聊天界面

我希望保留当前使用的功能,但解决LinearLayout被溢出的问题。当前功能是通过以下代码实现的:

getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_ADJUST_PAN);

以下是承载EditText和按钮的LinearLayout的XML代码:

<LinearLayout
        android:id="@+id/linearLayout"
        android:layout_width="0dp"
        android:layout_height="wrap_content"
        android:background="@color/blue_bar_background"
        android:orientation="horizontal"
        app:layout_constraintBottom_toBottomOf="parent"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintStart_toStartOf="parent">

        <EditText
            android:id="@+id/et_message"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_gravity="center|start"
            android:layout_marginTop="8dp"
            android:layout_marginBottom="8dp"
            android:layout_weight="1"
            android:background="@null"
            android:ems="10"
            android:focusedByDefault="true"
            android:hint="Type a message "
            android:maxLines="4"
            android:minHeight="48dp"
            android:paddingStart="8dp"
            android:paddingTop="8dp"
            android:paddingBottom="8dp"
            android:scrollHorizontally="true"
            android:singleLine="false"
            android:textColor="@color/white"
            android:textColorHint="#A8FFFFFF"
            android:textSize="20sp"
            app:layout_constraintBottom_toBottomOf="parent" />

        <com.google.android.material.floatingactionbutton.FloatingActionButton
            android:id="@+id/fab_addMessage"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_gravity="bottom|end"
            android:layout_weight="0"
            android:backgroundTint="@color/blue_bar_background"
            android:clickable="true"
            android:contentDescription="@string/app_name"
            android:elevation="0dp"
            android:src="@drawable/ic_round_send_24"
            app:borderWidth="0dp"
            app:elevation="0dp"
            app:tint="@color/white" />
    </LinearLayout>

若需要更多代码,请在评论中告知,感谢您的时间。

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.08.22 21:21:26