Android开发软键盘遮挡登陆按钮的完美解决方案

作者:poet 时间:2022-05-09 07:44:47 

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

1:登陆布局界面如下


<?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:background="@drawable/login_bg" >
<LinearLayout
android:id="@+id/ll_center"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="vertical" >
<ScrollView
android:id="@+id/sl_center"
android:layout_width="fill_parent"
android:layout_height="0dp"
android:layout_weight="1"
android:fadingEdge="none"
android:scrollbars="none" >
<RelativeLayout
android:id="@+id/rl_center"
android:layout_width="fill_parent"
android:layout_height="wrap_content" >
<LinearLayout
android:id="@+id/sms_login_ll_title"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:layout_marginTop="90dip"
android:orientation="horizontal" >
<ImageView
android:id="@+id/sms_login_iv_icon"
android:layout_width="70dip"
android:layout_height="70dip"
android:layout_gravity="center_vertical"
android:src="@drawable/login_top_icon" />
<ImageView
android:id="@+id/sms_login_iv_big_text"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical"
android:layout_marginLeft="15dip"
android:src="@drawable/sms_login_icon_big" />
</LinearLayout>
<ImageView
android:id="@+id/sms_login_iv_name"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@id/sms_login_ll_title"
android:layout_centerHorizontal="true"
android:layout_marginTop="28dip"
android:background="@drawable/sms_login_icon_small" />
<RelativeLayout
android:id="@+id/sms_login_rl_input_name"
android:layout_width="fill_parent"
android:layout_height="43dip"
android:layout_below="@id/sms_login_iv_name"
android:layout_centerHorizontal="true"
android:layout_marginLeft="40dip"
android:layout_marginRight="40dip"
android:layout_marginTop="40dip"
android:background="@drawable/login_top_input" >
<ImageView
android:id="@+id/sms_login_iv_input_name_icon"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_centerVertical="true"
android:layout_marginLeft="10dip"
android:layout_marginRight="10dip"
android:background="@drawable/login_input_icon_user" />
<FrameLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_centerVertical="true"
android:layout_toRightOf="@id/sms_login_iv_input_name_icon" >
<EditText
android:id="@+id/sms_login_et_accout"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:background="@drawable/transparent_white"
android:digits="@string/sms_login_accout_text"
android:hint="请输入账号"
android:singleLine="true"
android:text=""
android:textSize="20sp" />
</FrameLayout>
</RelativeLayout>
<RelativeLayout
android:id="@+id/sms_login_rl_input_pass"
android:layout_width="fill_parent"
android:layout_height="43dip"
android:layout_below="@id/sms_login_rl_input_name"
android:layout_centerHorizontal="true"
android:layout_marginLeft="40dip"
android:layout_marginRight="40dip"
android:background="@drawable/login_top_input" >
<ImageView
android:id="@+id/sms_login_iv_input_pass_icon"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_centerVertical="true"
android:layout_marginLeft="10dip"
android:layout_marginRight="10dip"
android:background="@drawable/login_input_icon_pwd" />
<FrameLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_centerVertical="true"
android:layout_toRightOf="@id/sms_login_iv_input_pass_icon" >
<EditText
android:id="@+id/sms_login_et_password"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:background="@drawable/transparent_white"
android:digits="@string/sms_et_change_password_old_text"
android:hint="请输入密码"
android:inputType="textPassword"
android:singleLine="true"
android:text=""
android:textSize="20sp" />
</FrameLayout>
</RelativeLayout>
</RelativeLayout>
</ScrollView>
<Button
android:id="@+id/sms_login_bt_confirm"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_below="@id/sms_login_rl_input_pass"
android:layout_centerHorizontal="true"
android:layout_marginLeft="40dip"
android:layout_marginRight="40dip"
android:layout_marginTop="16dip"
android:background="@drawable/sms_update_pass_bg_selector"
android:text="登 录"
android:textColor="@color/white"
android:textSize="20sp" />
</LinearLayout>
</RelativeLayout>

需要注意的是:

1:层级关系

RelativeLayout-----

LinearLayout----

ScrollView,

Button

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

3:看如下代码


etAccount = (EditText) this.findViewById(R.id.sms_login_et_accout);
etAccount.setOnClickListener(this);
etAccount.setOnTouchListener(new OnTouchListener() {
@Override
public boolean onTouch(View v, MotionEvent event) {
changeScrollView();
return false;
}
});
/**
* 使ScrollView指向底部
*/
private void changeScrollView(){
h.postDelayed(new Runnable() {
@Override
public void run() {
sl_center.scrollTo(0, sl_center.getHeight());
}
}, 300);
}
Handler h = new Handler(){
public void handleMessage(Message msg) {
};
};

以上所述是小编给大家介绍的Android开发软键盘遮挡登陆按钮的完美解决方案网站的支持!

来源:http://blog.csdn.net/yigelangmandeshiren/article/details/24982609

标签:android,软键盘,遮挡
0
投稿

猜你喜欢

  • 身份证号码验证算法深入研究和Java实现

    2023-05-18 08:17:42
  • C#实现Xml序列化与反序列化的方法

    2022-07-26 22:16:23
  • Android用Canvas绘制贝塞尔曲线

    2022-11-22 00:23:11
  • 双重检查锁定模式Java中的陷阱案例

    2023-11-13 22:11:02
  • C# 时间与时间戳互转的方法(13位)

    2023-12-04 10:26:39
  • Flutter 日历组件简单实现

    2023-10-21 11:04:35
  • java web中 HttpClient模拟浏览器登录后发起请求

    2022-10-27 23:07:05
  • WPF实现3D翻牌式倒计时特效

    2021-11-11 16:08:21
  • 浅谈JAVA并发之ReentrantLock

    2022-10-22 10:03:33
  • SpringBoot接口调用之后报404问题的解决方案

    2021-08-31 15:25:03
  • C#移除字符串中的不可见Unicode字符 案例代码

    2023-04-28 19:06:06
  • 教你快速搭建sona服务及idea使用sona的方法

    2023-11-20 05:22:53
  • Java面向对象编程(封装/继承/多态)实例解析

    2023-11-11 11:33:09
  • 图形学之Unity渲染管线流程分析

    2023-09-25 05:27:36
  • Android带进度的圆形进度条

    2023-08-05 21:47:18
  • Java多线程之同步锁-lock详解

    2023-12-16 14:40:08
  • SpringBoot整合第三方技术的详细步骤

    2023-11-29 08:22:48
  • C#实现获取机器码的示例详解

    2021-11-13 06:57:19
  • java 算法之快速排序实现代码

    2023-01-30 01:44:59
  • 详解用Eclipse如何创建Web项目

    2023-11-11 05:41:01
  • asp之家 软件编程 m.aspxhome.com