Android 软键盘顶起布局相关
原文链接:http://blog.csdn.net/mr_liu_gege/article/details/53169359
拾人牙慧,感谢博主分享。试验了一下,确实有效果,收藏学习。
第一种情况:被键盘遮住的按钮没有位于布局的底部
代码:
- <?xml version="1.0" encoding="utf-8"?>
- <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
- android:layout_width="match_parent"
- android:layout_height="wrap_content"
- android:orientation="vertical"
- android:id="@+id/parent_ll">
- <EditText
- android:id="@+id/username"
- android:layout_width="match_parent"
- android:layout_height="wrap_content"
- android:layout_marginTop="200dp"
- android:ems="10" >
- </EditText>
- <EditText
- android:id="@+id/userpwd"
- android:layout_width="match_parent"
- android:layout_height="wrap_content"
- android:layout_marginTop="30dp"
- android:ems="10"
- android:inputType="textPassword" />
- <Button
- android:id="@+id/btn"
- android:layout_width="wrap_content"
- android:layout_height="wrap_content"
- android:layout_gravity="center"
- android:layout_marginTop="30dp"
- android:text="Button" />
- </LinearLayout>
- public class MainActivity extends Activity {
- private Button btn;
- private LinearLayout parent_ll;
- @Override
- protected void onCreate(Bundle savedInstanceState) {
- super.onCreate(savedInstanceState);
- setContentView(R.layout.layout_login);
- /*ScrollView mScrollView = (ScrollView)findViewById(R.id.scrollContent);
- mScrollView.setVerticalScrollBarEnabled(false);
- mScrollView.setHorizontalScrollBarEnabled(false);*/
- parent_ll=(LinearLayout) findViewById(R.id.parent_ll);
- btn=(Button) findViewById(R.id.btn);
- addLayoutListener(parent_ll, btn);
- }
- /**
- * 1、获取parentView在窗体的可视区域
- * 2、获取parentView在窗体的不可视区域高度
- * 3、判断不可视区域高度
- * 1、大于100:键盘显示 获取childView的窗体坐标
- * 算出parentView需要滚动的高度,使childView显示。
- * 2、小于100:键盘隐藏
- *
- * @param parentView 根布局
- * @param childView 需要显示的最下方View
- */
- public void addLayoutListener(final View parentView, final View childView) {
- parentView.getViewTreeObserver().addOnGlobalLayoutListener(new ViewTreeObserver.OnGlobalLayoutListener() {
- @Override
- public void onGlobalLayout() {
- Rect rect = new Rect();
- parentView.getWindowVisibleDisplayFrame(rect);
- int mainInvisibleHeight = parentView.getRootView().getHeight() - rect.bottom;
- if (mainInvisibleHeight > 100) {
- int[] location = new int[2];
- childView.getLocationInWindow(location);
- int srollHeight = (location[1] + childView.getHeight()) - rect.bottom;
- parentView.scrollTo(0, srollHeight);
- } else {
- parentView.scrollTo(0, 0);
- }
- }
- });
- }
- }
addLayoutListener() 这个方法是关键。
第二种情况:被键盘遮住的按钮位于布局的底部
父布局需要是Relativelayout,按钮需要alignParentBottom,可能清单文件还需要设置android:windowSoftInputMode
Android 软键盘顶起布局相关相关推荐
- android虚拟键盘挡住布局,让Android软键盘不遮挡布局
在Android UI中,我们常常会使用EditText,比如在一个ScrollView中放置多个EditText,如下图: 带有edittext的scrollview.png 当用户点击这个Edit ...
- android软键盘顶部定义布局,Android 软键盘弹出时把原来布局顶上去的解决方法
键盘弹出时,会将布局底部的导航条顶上去. 解决办法: 在mainfest.xml中,在和导航栏相关的activity中加: android:name=".filing.MainActivit ...
- android 软键盘弹出 布局上移动
这是软件盘和actiivty主窗口抢空间造成的,需在AndroidManifest.xml里为activity配置windowSoftInputMode属性并为其选择属性值. 如下: <acti ...
- android键盘有缅甸文,外文翻译 - 有效的缅甸ANDROID软键盘的关键布局设计分析.doc...
外文原文 EFFECTIVE MYANMAR KEY LAYOUT DESIGN ANALYZING FOR ANDROID SOFT KEYBOARD NANDAR PWINT OO Tutor U ...
- Android 软键盘弹出时把布局顶上去,控件乱套解决方法
Android 软键盘弹出时把布局顶上去,控件乱套解决方法 参考文章: (1)Android 软键盘弹出时把布局顶上去,控件乱套解决方法 (2)https://www.cnblogs.com/zhuj ...
- Android 软键盘弹出时布局内指定内容上移实现及问题解决
Android 软键盘弹出时布局内指定内容上移实现及问题解决 参考文章: (1)Android 软键盘弹出时布局内指定内容上移实现及问题解决 (2)https://www.cnblogs.com/as ...
- Android 软键盘弹出时把原来布局顶上去的解决方法
Android 软键盘弹出时把原来布局顶上去的解决方法 参考文章: (1)Android 软键盘弹出时把原来布局顶上去的解决方法 (2)https://www.cnblogs.com/Joanna-Y ...
- Android软键盘手动显示、隐藏、布局上移和EditText上移
主要实现:Android软键盘手动显示.隐藏.布局上移和EditText上移 AndroidManifest.xml <?xml version="1.0" encoding ...
- android 软键盘和布局的冲突
最近公司在做一个项目是总是出现软键盘和布局的不兼容问题,这里我就随便记录下我自己查询得来的一些小知识: 一般来说解决软键盘的冲突有两种方法,一种是软键盘把布局文件顶上去,另一种是软键盘将布局文件给隐藏 ...
- android软键盘弹出底部有黑色闪出,vue移动端安卓软键盘弹出底部按钮顶起
在做一个基于企业微信的h5移动页面时,当软键盘弹出时,底部fixed定位在ios上没事,安卓手机上,底部按钮会被顶起到软键盘,查看原应时由于软键盘顶起时,安卓设备的视图会变小.造成固定定位按钮呗顶起. ...
最新文章
- 人脸属性迁移学习笔记
- python、PyTorch图像读取与numpy转换
- APP元素事件操作API
- python下几种打开文件的方式
- java正则 环视_正则表达式之环视(java)
- WIN10 开启右键 命令提示符
- java uuid静态方法_Java UUID toString()方法与示例
- C语言 abort 函数 - C语言零基础入门教程
- MyBatis各个jar包的作用
- ie6的png24问题
- phpmailer 与 mail
- 将Matlab换成Pycharm风格
- 接口测试工具--Postman安装
- 【Adobe Illustrator 教程】4. 认识渐变工具
- 怎样在两台计算机之间建立硬盘共享,如何让两台电脑硬盘共享在一起
- YY一下淘宝商品模型
- 一次错综离奇的super调用的None参数super() argument 1 must be type, not None
- FastText学习笔记
- 二叉树的顺序存储和三种遍历(二)
- 【报告分享】数观食机|2020快手食品行业数据价值报告-磁力引擎-202103.pdf(附下载地址)