弹出键盘遮挡按钮的处理方法
来源:互联网 发布:网络隔离卡作用 编辑:程序博客网 时间:2024/05/01 21:28
在有的界面上我们要让用户输入一些东西,输完东西后,用户就要按”确定”按钮保存,或者按”取消”按钮取消操作,如下面一图中的操作:
当用户点击上面的输入框时,这个时候,软键盘就会自动弹出来,用户输入完成后,那用户还得按一下返回键,用户才能看到“确定”和“取消”按键,这样用户就有点麻烦,如果用户在上面的输入入框中输入后,就想直接保存,而不用再按一下返回键。
也就是当用户点击输入框的时候,键盘弹出来,同时下面的”确定”和”取消”这两个按钮也同时向上移动,停靠在软键盘之上。就像下面这张图片:
这个怎么实现呢,看下面的图:
按照上面图里面这样布局,那么当键盘弹出的时候,下面一块就都要向上抬起,停靠在键盘之上,在有的时候,这样比较方便用户输入完成后提交或取消。
这个里面还必须要有一个ScollView,或者ListView,ExtanspabeListView等的一个组件,之间没有说,现在补上,并附代码:
<?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" android:orientation="vertical" > <EditText android:layout_width="fill_parent" android:layout_height="wrap_content" android:inputType="text"/> <ScrollView android:layout_width="match_parent" android:layout_height="0dp"> </ScrollView> <LinearLayout style="@android:style/ButtonBar" android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_alignParentBottom="true" android:orientation="horizontal" > <Button android:layout_width="0dip" android:layout_height="wrap_content" android:layout_weight="1" android:text="确定" /> <Button android:layout_width="0dip" android:layout_height="wrap_content" android:layout_weight="1" android:text="取消" /> </LinearL`yout> </RelativeLayout>
经过测试,最外面如果那么里面的那个“确定”和“取消”所在的布局必须在最下面要用weight属性,并且也要有ListView或ScollView如下面的代码,这个也要ScollView等开始的位置在弹出的键盘的上面开始,这个设置不好容易出错,最好的就是上面的方法:
<?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="match_parent" android:orientation="vertical" > <EditText android:layout_width="fill_parent" android:layout_height="wrap_content" android:inputType="text"/> <ScrollView android:layout_width="match_parent" android:layout_height="0dp" android:layout_weight="1"> </ScrollView> <LinearLayout style="@android:style/ButtonBar" android:layout_width="match_parent" android:layout_height="wrap_content" android:orientation="horizontal" > <Button android:layout_width="0dip" android:layout_height="wrap_content" android:layout_weight="1" android:text="确定" /> <Button android:layout_width="0dip" android:layout_height="wrap_content" android:layout_weight="1" android:text="取消" /> </LinearLayout> </LinearLayout>
0 0
- 弹出键盘遮挡按钮的处理方法
- 处理键盘遮挡视图的方法
- android虚拟键盘弹出遮挡登陆按钮问题
- UITextField键盘弹出遮挡的解决
- 软键盘遮挡登录按钮的处理方法
- [操作系统]处理UIScrollView中的编辑框被弹出键盘遮挡的问题
- 处理键盘消失和遮挡的问题
- UITableView处理键盘遮挡
- IOS 键盘遮挡处理
- iOS 键盘遮挡处理
- UITextField被弹出键盘遮挡
- ios关于键盘遮挡的简单方法
- iOS 解决键盘被遮挡的方法
- 最简单的方法搞定键盘遮挡
- 关于键盘弹出后遮挡屏幕的解决办法
- 弹出键盘时遮挡输入框的问题解决
- iOS 弹出的键盘被window遮挡住了
- 对键盘弹出的处理
- unity3d研究之视频播放
- 异常处理之不要放过First-chance exception
- html5开发之viewport使用
- android Application.mk文件的APP_MODULES:
- void main与int main(void)
- 弹出键盘遮挡按钮的处理方法
- unity游戏开发之防空防灾游戏来了 防雾霾的游戏还会远么
- android 带你从源码的角度解析Scroller的滚动实现原理
- unity第一天
- 安卓-屏幕适配方式
- session标签(对会话进行增、删、改)
- Android Studio Tips -- 布局预览
- Windows Azure - CloudService Introduction - 01
- STL算法------最小值和最大值