android实现软键盘弹出,editText随键盘上移,背景不动

前段时间有个妹子问我如题的需求,我就想,这种东西网上不是很多吗,自己试过才发现,基本都不行,各种设置配置文件的windowSoftInputMode,要么背景被压缩,要么背景向上移动,要么背景不动,但是editText没有跟着动,只能自己潜心研究,找到一种方案,虽然不完美,但是基本能满足大部分人的这类需求。

老规矩,先看效果,再贴代码:
键盘隐藏

键盘弹出

下面是代码部分:

public class EditMoveActivity extends Activity {private ImageView imageView;@Overridepublic void onCreate(Bundle savedInstanceState) {super.onCreate(savedInstanceState);setContentView(R.layout.activity_edit_move);imageView = (ImageView) findViewById(R.id.imageView);Rect outRect = new Rect();getWindow().getDecorView().getWindowVisibleDisplayFrame(outRect);LinearLayout.LayoutParams params = (LinearLayout.LayoutParams) imageView.getLayoutParams();params.height = outRect.bottom - outRect.top;}
}<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"android:layout_width="match_parent"android:layout_height="match_parent"><ScrollViewandroid:layout_width="match_parent"android:layout_height="match_parent"android:overScrollMode="never"android:scrollbars="none"><LinearLayoutandroid:id="@+id/linearLayout"android:layout_width="match_parent"android:layout_height="match_parent"android:orientation="vertical"><ImageViewandroid:id="@+id/imageView"android:layout_width="match_parent"android:layout_height="match_parent"android:scaleType="centerCrop"android:src="@drawable/bg"/></LinearLayout></ScrollView><RelativeLayoutandroid:id="@+id/viewEdit"android:layout_width="match_parent"android:layout_height="60dp"android:layout_alignParentBottom="true"android:background="#88f1abcd"><EditTextandroid:id="@+id/editText"android:layout_width="match_parent"android:layout_height="60dp"android:layout_alignParentBottom="true" /></RelativeLayout>
</RelativeLayout><?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"package="com.zhangxq.editmove"><applicationandroid:allowBackup="true"android:icon="@mipmap/ic_launcher"android:label="@string/app_name"android:supportsRtl="true"android:theme="@style/AppTheme"><activityandroid:name=".EditMoveActivity"android:windowSoftInputMode="adjustResize"><intent-filter><action android:name="android.intent.action.MAIN" /><category android:name="android.intent.category.LAUNCHER" /></intent-filter></activity></application></manifest>

可以看到代码很简单,需要注意的只有这么几点:

  1. 看第18行,效果基本上是依靠布局文件来实现的,布局文件最外层需要是RelativeLayout,(FrameLayout应该也行,我没有试过)。
  2. 看第22行,不能移动的部分(这里使用ImageView举例)需要放在一个LinearLayout或者RelativeLayout里,并且外层需要套一个ScrollView,少一层都不行。
  3. 看第10行,需要在代码中动态设置不能移动部分的高度(这里用ImageView举例)。
  4. 看第69行,配置文件需要设置:android:windowSoftInputMode=“adjustResize”
  5. 至于我说的不完美的地方是:如果你需要通过setFlag的方式隐藏状态栏,那么背景还是会上移。

android实现软键盘弹出,editText随键盘上移,背景不动相关推荐

  1. 小程序中点击input控件键盘弹出时placeholder文字上移

    最近做的一个小程序项目中,出现了点击input控件键盘弹出时placeholder文字上移,刚开始以为是软键盘弹出布局上移问题是传说中典型的fixed 软键盘顶起问题,因此采纳了网上搜到的" ...

  2. (转)Android软键盘弹出,界面整体上移

    原地址:http://blog.csdn.net/u011622479/article/details/51161717 在做搜索功能的时候,点击搜索框,搜索框获取焦点,键盘弹出:现在问题出来了,an ...

  3. axure键盘弹出_AxureRP实现键盘交互效果

    与键盘的交互一般都简化成输入内容,或者改为由鼠标来控制会比较多,因为B/S架构的系统或者网站其实不大需要跟键盘有交互,用鼠标就可以全部都实现了,这也是为了提升用户体验的满意度.不过现在网页游戏这么流行 ...

  4. Android 软键盘弹出,界面整体上移的问题

    AndroidManifest.xml文件中界面对应的<activity>里加入 android:windowSoftInputMode="adjustPan" 键盘就 ...

  5. Android软键盘弹出和收起的监听

    Android软键盘弹出和收起的监听 1.直接调用 SoftKeyboardHelper softKeyboardHelper = softKeyboardHelper = new SoftKeybo ...

  6. Android 软键盘 弹出,默认隐藏,强制隐藏,自动变大写等

    经常时不时的需要控制软键盘的不同状态,每次用每次查,自己总结一下所有关于Android软键盘的东西写一块. 1.代码中弹出/隐藏软键盘: //view为接受软键盘输入的视图,SHOW_FORCED表示 ...

  7. android 软件盘未弹出如何获取高度,Android 软键盘的那些坑,一招搞定!

    3 软键盘高度获取 对于上面的问题1,既然想要EditText单独顶上去,那么就需要知道当前键盘弹出的高度,再设置EditText坐标即可. 问题的关键转变为如何获取键盘的高度. Activity窗口 ...

  8. Android判断软键盘弹出并隐藏的简单完美解决方案

    Android判断软键盘弹出并隐藏的简单完美解决方案 参考文章: (1)Android判断软键盘弹出并隐藏的简单完美解决方案 (2)https://www.cnblogs.com/thare1307/ ...

  9. Android 软键盘弹出时布局内指定内容上移实现及问题解决

    Android 软键盘弹出时布局内指定内容上移实现及问题解决 参考文章: (1)Android 软键盘弹出时布局内指定内容上移实现及问题解决 (2)https://www.cnblogs.com/as ...

最新文章

  1. Unity 字典实现
  2. 初探 Vue 生命周期和钩子函数
  3. SAP 自定义 Table 中的小陷阱
  4. 深拷贝拯救指针重复释放(浅拷贝)造成的内存泄漏
  5. MySQL使用时遇到的问题
  6. close 不弹出对话框
  7. 铺砖问题JAVA_java彩色瓷砖编程题分析
  8. 新版蓝色广告跳转页面代码分享
  9. MySQL 历史版本安装和下载
  10. Linux各类压宿包的压缩和解压方法
  11. 常用电源及稳压芯片(一)
  12. SDWebImage获取到UIImage分辨率跟原图不一样
  13. Destroy与DestroyImmediate以及引发的bug
  14. 注册表的基本操作(.Net)
  15. Flightgear操作方式以及几种典型飞机的起飞方法
  16. 智慧博物馆信息系统建设方案
  17. php 股票数据 sina,使用Sina API获取新浪财经的证券股票数据接口(时价 K线等)
  18. 江苏计算机等级考试二级office题库,2020年江苏省计算机二级Office考试易考套餐:二级MS Office高级应用全程班(网课+题库)...
  19. 怎样用VR看分频视频?
  20. 24位真彩色图片取摸方法(用于WS2812显示)

热门文章

  1. clover无缘无故隐藏书签栏原因
  2. angular:带验证功能的formControlName的select下拉框数据充填
  3. GD32 spi通信
  4. 无需一行代码就能搞定机器学习的开源神器
  5. aelf技术点解读 | 分红合约接口实现方案
  6. 微信检测域名防封系统 如何调用微信官方的微信域名检测接口API
  7. Android键盘显示和隐藏
  8. wxpython列表框_wxpython中列表框(ListBox类)、复选列表框(CheckListBox)、下拉选项(Choice)、进度条(Gauge)、滑块(Slider)使用实例源码分享...
  9. 获取钉钉花名册接口和枚举类
  10. php怎么实现拼图功能,布局拼图功能实现