软键盘遮挡

2024-05-05 03:18
文章标签 软键盘 遮挡

本文主要是介绍软键盘遮挡,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!

在应用登陆页面我们需要填写用户名和密码。当填写这些信息的时候,软键盘会遮挡登陆按钮,这使得用户体验较差,所以今天就来解决这个问题

1:登陆布局界面如下

[html]  view plain copy print ? 在CODE上查看代码片 派生到我的代码片
  1. <?xml version="1.0" encoding="utf-8"?>  
  2. <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"  
  3.     android:layout_width="match_parent"  
  4.     android:layout_height="match_parent"  
  5.     android:background="@drawable/login_bg" >  
  6.   
  7.     <LinearLayout  
  8.         android:id="@+id/ll_center"  
  9.         android:layout_width="fill_parent"  
  10.         android:layout_height="wrap_content"       
  11.         android:orientation="vertical" >  
  12.   
  13.         <ScrollView  
  14.             android:id="@+id/sl_center"  
  15.             android:layout_width="fill_parent"  
  16.             android:layout_height="0dp"  
  17.             android:layout_weight="1"  
  18.             android:fadingEdge="none"  
  19.             android:scrollbars="none" >  
  20.   
  21.             <RelativeLayout  
  22.                 android:id="@+id/rl_center"  
  23.                 android:layout_width="fill_parent"  
  24.                 android:layout_height="wrap_content" >  
  25.   
  26.                 <LinearLayout  
  27.                     android:id="@+id/sms_login_ll_title"  
  28.                     android:layout_width="wrap_content"  
  29.                     android:layout_height="wrap_content"  
  30.                     android:layout_centerHorizontal="true"  
  31.                     android:layout_marginTop="90dip"  
  32.                     android:orientation="horizontal" >  
  33.   
  34.                     <ImageView  
  35.                         android:id="@+id/sms_login_iv_icon"  
  36.                         android:layout_width="70dip"  
  37.                         android:layout_height="70dip"  
  38.                         android:layout_gravity="center_vertical"  
  39.                         android:src="@drawable/login_top_icon" />  
  40.   
  41.                     <ImageView  
  42.                         android:id="@+id/sms_login_iv_big_text"  
  43.                         android:layout_width="wrap_content"  
  44.                         android:layout_height="wrap_content"  
  45.                         android:layout_gravity="center_vertical"  
  46.                         android:layout_marginLeft="15dip"  
  47.                         android:src="@drawable/sms_login_icon_big" />  
  48.                 </LinearLayout>  
  49.   
  50.                 <ImageView  
  51.                     android:id="@+id/sms_login_iv_name"  
  52.                     android:layout_width="wrap_content"  
  53.                     android:layout_height="wrap_content"  
  54.                     android:layout_below="@id/sms_login_ll_title"  
  55.                     android:layout_centerHorizontal="true"  
  56.                     android:layout_marginTop="28dip"  
  57.                     android:background="@drawable/sms_login_icon_small" />  
  58.   
  59.                 <RelativeLayout  
  60.                     android:id="@+id/sms_login_rl_input_name"  
  61.                     android:layout_width="fill_parent"  
  62.                     android:layout_height="43dip"  
  63.                     android:layout_below="@id/sms_login_iv_name"  
  64.                     android:layout_centerHorizontal="true"  
  65.                     android:layout_marginLeft="40dip"  
  66.                     android:layout_marginRight="40dip"  
  67.                     android:layout_marginTop="40dip"  
  68.                     android:background="@drawable/login_top_input" >  
  69.   
  70.                     <ImageView  
  71.                         android:id="@+id/sms_login_iv_input_name_icon"  
  72.                         android:layout_width="wrap_content"  
  73.                         android:layout_height="wrap_content"  
  74.                         android:layout_alignParentLeft="true"  
  75.                         android:layout_centerVertical="true"  
  76.                         android:layout_marginLeft="10dip"  
  77.                         android:layout_marginRight="10dip"  
  78.                         android:background="@drawable/login_input_icon_user" />  
  79.   
  80.                     <FrameLayout  
  81.                         android:layout_width="fill_parent"  
  82.                         android:layout_height="wrap_content"  
  83.                         android:layout_centerVertical="true"  
  84.                         android:layout_toRightOf="@id/sms_login_iv_input_name_icon" >  
  85.   
  86.                         <EditText  
  87.                             android:id="@+id/sms_login_et_accout"  
  88.                             android:layout_width="fill_parent"  
  89.                             android:layout_height="wrap_content"  
  90.                             android:background="@drawable/transparent_white"  
  91.                             android:digits="@string/sms_login_accout_text"  
  92.                             android:hint="请输入账号"  
  93.                             android:singleLine="true"  
  94.                             android:text=""  
  95.                             android:textSize="20sp" />  
  96.                     </FrameLayout>  
  97.                 </RelativeLayout>  
  98.   
  99.                 <RelativeLayout  
  100.                     android:id="@+id/sms_login_rl_input_pass"  
  101.                     android:layout_width="fill_parent"  
  102.                     android:layout_height="43dip"  
  103.                     android:layout_below="@id/sms_login_rl_input_name"  
  104.                     android:layout_centerHorizontal="true"  
  105.                     android:layout_marginLeft="40dip"  
  106.                     android:layout_marginRight="40dip"  
  107.                     android:background="@drawable/login_top_input" >  
  108.   
  109.                     <ImageView  
  110.                         android:id="@+id/sms_login_iv_input_pass_icon"  
  111.                         android:layout_width="wrap_content"  
  112.                         android:layout_height="wrap_content"  
  113.                         android:layout_alignParentLeft="true"  
  114.                         android:layout_centerVertical="true"  
  115.                         android:layout_marginLeft="10dip"  
  116.                         android:layout_marginRight="10dip"  
  117.                         android:background="@drawable/login_input_icon_pwd" />  
  118.   
  119.                     <FrameLayout  
  120.                         android:layout_width="fill_parent"  
  121.                         android:layout_height="wrap_content"  
  122.                         android:layout_centerVertical="true"  
  123.                         android:layout_toRightOf="@id/sms_login_iv_input_pass_icon" >  
  124.   
  125.                         <EditText  
  126.                             android:id="@+id/sms_login_et_password"  
  127.                             android:layout_width="fill_parent"  
  128.                             android:layout_height="wrap_content"  
  129.                             android:background="@drawable/transparent_white"  
  130.                             android:digits="@string/sms_et_change_password_old_text"  
  131.                             android:hint="请输入密码"  
  132.                             android:inputType="textPassword"  
  133.                             android:singleLine="true"  
  134.                             android:text=""  
  135.                             android:textSize="20sp" />  
  136.                     </FrameLayout>  
  137.                 </RelativeLayout>  
  138.             </RelativeLayout>  
  139.         </ScrollView>  
  140.   
  141.         <Button  
  142.             android:id="@+id/sms_login_bt_confirm"  
  143.             android:layout_width="fill_parent"  
  144.             android:layout_height="wrap_content"  
  145.             android:layout_below="@id/sms_login_rl_input_pass"  
  146.             android:layout_centerHorizontal="true"  
  147.             android:layout_marginLeft="40dip"  
  148.             android:layout_marginRight="40dip"  
  149.             android:layout_marginTop="16dip"  
  150.             android:background="@drawable/sms_update_pass_bg_selector"  
  151.             android:text="登 录"  
  152.             android:textColor="@color/white"  
  153.             android:textSize="20sp" />  
  154.     </LinearLayout>  
  155.    
  156. </RelativeLayout>  

需要注意的是:

1:层级关系

RelativeLayout-----

    LinearLayout----

     ScrollView,  

     Button

2:在AndroidManifest.xml中的该activity配置  android:windowSoftInputMode="stateHidden|adjustResize"

3:看如下代码

[java]  view plain copy print ? 在CODE上查看代码片 派生到我的代码片
  1. etAccount = (EditText) this.findViewById(R.id.sms_login_et_accout);  
  2.         etAccount.setOnClickListener(this);  
  3.         etAccount.setOnTouchListener(new OnTouchListener() {  
  4.             @Override  
  5.             public boolean onTouch(View v, MotionEvent event) {  
  6.                 changeScrollView();   
  7.                 return false;  
  8.             }  
  9.         });  
  10.     /** 
  11.      * 使ScrollView指向底部 
  12.      */  
  13.     private void changeScrollView(){  
  14.         h.postDelayed(new Runnable() {  
  15.             @Override  
  16.             public void run() {  
  17.                 sl_center.scrollTo(0, sl_center.getHeight());   
  18.             }  
  19.         }, 300);  
  20.     }  
  21.       
  22.     Handler h = new Handler(){  
  23.         public void handleMessage(Message msg) {  
  24.         };  
  25.     };  

4:具体问题具体分析,方法有多种,欢迎大家讨论。

这篇关于软键盘遮挡的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!



http://www.chinasem.cn/article/960698

相关文章

Android 自定义软键盘实现 数字九宫格

最近项目在对接美团外卖功能 实现外面小哥凭取货码取货 对接完功能后 用户反馈 弹出的软键盘 很难输入 数字太小了 大概是下面这种显示方式 需求 组长说 要不搞一个自定义软键盘吧 数字搞大点 方便外卖员输入数字 我设置了输入EditText的输入格式为Number 还是不行 那就开搞吧 先来看下实现的效果图吧 实现效果GIF 实现代码 自定义View 一个NineNume

Android 软键盘的处理

转载:http://blog.csdn.net/mynameishuangshuai/article/details/51567357 软键盘显示的原理 软件盘的本质是什么?软键盘其实是一个Dialog。 InputMethodService为我们的输入法创建了一个Dialog,并且将该Dialog的Window的某些参数(如Gravity)进行了设置,使之能够在底部或者全屏显示。当我们点击

手机客户端阻止手机软键盘弹出

手机网页怎么禁止缩放和拖动  禁止缩放 <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1, minimum-scale=1, user-scalable=no" /> user-scalable=no    yes 设置用户缩放 禁止拖动 documen

IOS 防止键盘遮挡文本框

在开发中我们经常会碰到键盘遮挡文本框的问题,在这里总结一下解决方法 将文本框的delegate设置为File's Owner或者使用代码textField.delegate=self; 在文本输入框所对应的类中实现UITextFieldDelegate协议,然后在其.m文件中实现UITextFieldDelegate的三个方法,三个方法代码如下: -(void)textFieldDidB

Android调用输入法软键盘,返回输入的内容

Android调用输入法软键盘,返回输入的内容                分类:            Android 2013-09-14 17:50 32人阅读 评论(0) 收藏 举报 Android NDK Android调出软键盘 InputMethodManager 我们一直在讲,C++写游戏代码,然后通过NDK编译,然后展现在Android层。 在游

Android开发:在EditText中关闭软键盘

Android开发:在EditText中关闭软键盘                分类:            android 2013-05-15 00:33 108人阅读 评论(0) 收藏 举报 Android开发:在EditText中关闭软键盘 博客分类: android 1、EditText有焦点(focusable为true)阻止输入法弹出  Java代

Android 搜索 把软键盘上的回车键改为搜索

Android    搜索   把软键盘上的回车键改为搜索                分类:            android 2013-03-29 15:16 820人阅读 评论(0) 收藏 举报 Android 效果就是在EditView上输入内容后,可以直接点击键盘上的搜索键【由之前的回车键改编而来】 步骤如下: 1. 修改Editview属性:andro

Element-UI - 解决el-table中图片悬浮被遮挡问题

在开发中,发现element-ui在el-table中添加图片悬浮显示时,会被单元格遮挡的问题。通过查询得到的解决办法,大多是修改.el-table类中相关样式属性,但经过验证发现会影响到其他正常功能的使用。对于此问题解决其实也并不难,将悬浮图片放在body节点下,通过定位显示即可。所以对于此问题,将通过Vue.directive钩子函数,自定义弹框来实现。 一、Vue.di

iPhone/iPad键盘弹出遮挡要编辑内…

iPhone/iPad键盘弹出遮挡要编辑内容问题 2011-04-02 16:17:31 标签: 键盘  iPhone  keyboard  遮盖  popover 原创作品,允许转载,转载时请务必以超链接形式标明文章  原始出处  、作者信息和本声明。否则将追究法律责任。 http://afantihust.blog.51cto.com/2231549/533976

Tinymce富文本编辑器在el-dialog中遮挡的问题

Tinymce的vue文件加上一下代码即可 <style lang="scss">.tox-tinymce-aux {z-index: 4000 !important;}</style>