android弹出输入框,软键盘挡住部分编辑框

发布于 2022-09-01 21:14:16 字数 2554 浏览 27 评论 0

公司要做一款类似微信的即时通讯app 现有如下需求:
当edittext获取到焦点,弹出输入框,并且将listview(recyclerview)顶上去 类似微信QQ的效果,如下图所示

图片描述

editText获取焦点后

图片描述


我试了如下几种方法

  1. 配置当前的Activity android:windowSoftInputMode="stateAlwaysHidden|adjustResize"

    缺点:listview(recyclerview)不会被顶上去

  2. 在1的基础上,当软键盘弹出的时候 发送延迟消息把 recyclerView 滚动到底部

    mHandler.postDelay()
    layoutManager.setStackFromEnd(true); // 滚动到底部
    缺点: 有时候滚不到底部 没效果

  3. 配置当前的Activity android:windowSoftInputMode="stateAlwaysHidden|adjustPan"

    缺点: 底部输入栏部分被挡住 软键盘会顶到光标的高度 如图

    图片描述

  4. 在3的基础上 修改editText的属性, 去掉所有margin值 增加paddingbottom
    基本可行..底部栏还是有部分会被挡住
    缺点: editText 太高了 与设计稿要求高度不符合

各位乡亲父老 即时通讯这块应该很多人做过吧...求指点啊啊啊

最后贴一下布局文件

<?xml version="1.0" encoding="utf-8"?>
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/fl_container"
    android:layout_width="match_parent"
    android:layout_height="match_parent">

    <RelativeLayout
        android:id="@+id/rl_content"
        android:layout_width="match_parent"
        android:layout_height="match_parent">
        <android.support.v4.widget.SwipeRefreshLayout
            android:id="@+id/fragment_chat_srl_pullrefresh"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:layout_above="@+id/fragment_chat_inputbottombar">

            <android.support.v7.widget.RecyclerView
                android:id="@+id/fragment_chat_rv_chat"
                android:layout_width="match_parent"
                android:layout_height="match_parent" />
        </android.support.v4.widget.SwipeRefreshLayout>
        
       <!--底部栏-->
        <cn.org.yxj.doctorstation.view.customview.InputBottomBar_
            android:id="@+id/fragment_chat_inputbottombar"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_alignParentBottom="true" />
    </RelativeLayout>
</FrameLayout>

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

旧梦荧光笔 2022-09-08 21:14:16

除了配置当前的Activity android:windowSoftInputMode="stateVisible|adjustResize"外,还需要:

listView.setTranscriptMode(ListView.TRANSCRIPT_MODE_NORMAL);

The list will automatically scroll to the bottom when a data set change notification is received and only if the last item is already visible on screen.

这样listview就根据key board的弹出/隐藏而自动滚动了。
recyclerview没有找到类似的API.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文