前言

就类似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>

更多相关文章

  1. Android(安卓)layout 优化:使用include和merge 标签
  2. android自定义布局中的平滑移动
  3. android 双向滑动 稍加改进,可做成QQHD效果
  4. Android控件开发之四----ListView(4)
  5. android 隐藏键盘 ----- 断点记录
  6. Android(安卓)使用RecyclerView的方法
  7. Android(安卓)-- PowerManager和PowerManager.WakeLock
  8. 使用ViewSwitcher和ViewFlipper在不同布局中切换
  9. android调用输入软键盘回车键跟删除键

随机推荐

  1. android设备你所应该知道的Android设计
  2. Android(安卓)Studio下Java Jni技术
  3. 谷歌使用AndroidX代替Android支持库
  4. 【Android的从零单排开发日记】之入门篇(
  5. 电子书 android高薪之路-android程序员面
  6. Android(安卓)Jetpack让Android一飞冲天
  7. Android天气预报详解
  8. 深入探讨 Android(安卓)传感器
  9. Android调用WebService系列之KSoap2对象
  10. [数据图表]Android军团超级黑马亚马逊平