Android使得底部输入框在输入法上边显示
16lz
2021-01-24
前言
就类似QQ和微信聊天时的样子,在输入框获取焦点,弹出输入法的时候,使得输入框在输入法的上边显示!
我在查阅了一些资料之后,下边几篇博客都提供了很好的思路:
android输入框在软键盘的上面
Android软件盘之使特定布局保持在软键盘之上
android中如何实现点击EditText输入框,其它布局悬浮在软键盘的上面
我的实例
上边的几篇文章,在一般的布局页面,基本上都能满足实现想要的效果,但是我在测试下边的这个布局页面的时候就不行了:
<?xml version="1.0" encoding="utf-8"?><LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent" android:layout_height="match_parent" android:orientation="vertical" tools:context=".MainActivity"> <TextView android:layout_width="match_parent" android:layout_height="wrap_content" android:padding="18dp" android:text="我是标题" /> <View android:layout_width="match_parent" android:layout_height="210dp" android:background="#000000" /> <View android:layout_width="match_parent" android:layout_height="50dp" android:background="#008577" /> <androidx.recyclerview.widget.RecyclerView android:layout_width="match_parent" android:layout_height="0dp" android:layout_weight="1"/> <LinearLayout android:layout_width="match_parent" android:layout_height="wrap_content" android:orientation="horizontal"> <EditText android:layout_width="0dp" android:layout_height="wrap_content" android:layout_weight="1" android:text="Hello World!" /> <TextView android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="发送" /> LinearLayout> LinearLayout>
就是类似一个简单的视频播放页面,在输入框布局上边是一个评论列表,而且这个列表设置的是充满剩余的整个空间!再使用上边的方法就不行了!
然后在测试了一下之后,发现如果输入框布局在底部,要想弹出输入法之后,使得底部输入框布局在输入法的上边,只需将输入框布局和输入框之上的布局设置成同级即可!别的什么都不需要设置,就可以实现我们想要的这种效果!
即:
<?xml version="1.0" encoding="utf-8"?><LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent" android:layout_height="match_parent" android:orientation="vertical" tools:context=".MainActivity"> <LinearLayout android:layout_width="match_parent" android:layout_height="0dp" android:layout_weight="1" android:orientation="vertical"> <TextView android:layout_width="match_parent" android:layout_height="wrap_content" android:padding="18dp" android:text="我是标题" /> <View android:layout_width="match_parent" android:layout_height="210dp" android:background="#000000" /> <View android:layout_width="match_parent" android:layout_height="50dp" android:background="#008577" /> <androidx.recyclerview.widget.RecyclerView android:layout_width="match_parent" android:layout_height="match_parent" /> LinearLayout> <LinearLayout android:layout_width="match_parent" android:layout_height="wrap_content" android:orientation="horizontal"> <EditText android:layout_width="0dp" android:layout_height="wrap_content" android:layout_weight="1" android:text="Hello World!" /> <TextView android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="发送" /> LinearLayout> LinearLayout>
更多相关文章
- Android(安卓)layout 优化:使用include和merge 标签
- android自定义布局中的平滑移动
- android 双向滑动 稍加改进,可做成QQHD效果
- Android控件开发之四----ListView(4)
- android 隐藏键盘 ----- 断点记录
- Android(安卓)使用RecyclerView的方法
- Android(安卓)-- PowerManager和PowerManager.WakeLock
- 使用ViewSwitcher和ViewFlipper在不同布局中切换
- android调用输入软键盘回车键跟删除键