Android输入框软键盘间距

https://blog.csdn.net/m0_37388625/article/details/106025262

纯笔记,无任何高科技,为了软键盘弹出时与输入框保持一点点的距离,使用ScrollView+LinearLayout包裹住输入框,ScrollView+LinearLayout的高度稍微比输入框高一点即可(无需java代码控制),效果如下图:

 

 

复制代码
<?xml version="1.0" encoding="utf-8"?>
<FrameLayout 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"
    tools:context=".MainActivity">

    <ScrollView
        android:layout_gravity="bottom"
        android:layout_width="match_parent"
        android:padding="5dp"
        android:background="@color/colorPrimaryDark"
        android:layout_height="60dp">

        <LinearLayout
            android:orientation="horizontal"
            android:layout_width="match_parent"
            android:layout_height="match_parent">

            <Button
                android:text="Click"
                android:layout_width="100dp"
                android:layout_height="match_parent" />

            <LinearLayout
                android:id="@+id/line_comment"
                android:layout_width="match_parent"
                android:layout_height="match_parent"
                android:layout_gravity="bottom"
                android:background="#f00"
                android:focusable="true"
                android:visibility="visible"
                android:focusableInTouchMode="true"
                android:gravity="center_vertical"
                android:orientation="vertical">
                <EditText
                    android:id="@+id/etComment"
                    android:layout_width="match_parent"
                    android:layout_height="40dp"
                    android:layout_marginLeft="12dp"
                    android:layout_marginTop="8dp"
                    android:layout_marginBottom="8dp"
                    android:layout_weight="1"
                    android:inputType="text"
                    android:background="#0f0"
                    android:hint="输入框hint..."
                    android:layout_marginRight="12dp"
                    android:imeOptions="actionSend"
                    android:maxLength="100"
                    android:paddingLeft="12dp"
                    android:textSize="16sp" />

                <View
                    android:id="@+id/viewKeyboard"
                    android:background="#00f"
                    android:layout_width="match_parent"
                    android:layout_height="0dp" />
            </LinearLayout>
        </LinearLayout>
    </ScrollView>
</FrameLayout>
复制代码

 

posted @   野生野鸡码农  阅读(972)  评论(1编辑  收藏  举报
编辑推荐:
· AI与.NET技术实操系列(二):开始使用ML.NET
· 记一次.NET内存居高不下排查解决与启示
· 探究高空视频全景AR技术的实现原理
· 理解Rust引用及其生命周期标识(上)
· 浏览器原生「磁吸」效果!Anchor Positioning 锚点定位神器解析
阅读排行:
· 全程不用写代码,我用AI程序员写了一个飞机大战
· DeepSeek 开源周回顾「GitHub 热点速览」
· 记一次.NET内存居高不下排查解决与启示
· MongoDB 8.0这个新功能碉堡了,比商业数据库还牛
· .NET10 - 预览版1新功能体验(一)
点击右上角即可分享
微信分享提示