【Android】解决软键盘遮挡登陆按钮
2014-05-09 14:14
295 查看
在应用登陆页面我们需要填写用户名和密码。当填写这些信息的时候,软键盘会遮挡登陆按钮,这使得用户体验较差,所以今天就来解决这个问题1:登陆布局界面如下
[html]view plaincopyprint?
<?xmlversion="1.0"encoding="utf-8"?>
<RelativeLayoutxmlns: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, Button2:在AndroidManifest.xml中的该activity配置 android:windowSoftInputMode="stateHidden|adjustResize"3:看如下代码
[java]view plaincopyprint?
etAccount = (EditText) this.findViewById(R.id.sms_login_et_accout);
etAccount.setOnClickListener(this);
etAccount.setOnTouchListener(new OnTouchListener() {
@Override
publicboolean onTouch(View v, MotionEvent event) {
changeScrollView();
returnfalse;
}
});
/**
* 使ScrollView指向底部
*/
privatevoid changeScrollView(){
h.postDelayed(new Runnable() {
@Override
publicvoid run() {
sl_center.scrollTo(0, sl_center.getHeight());
}
}, 300);
}
Handler h = new Handler(){
publicvoid handleMessage(Message msg) {
};
};
4:具体问题具体分析,方法有多种,欢迎大家讨论。
[html]view plaincopyprint?
<?xmlversion="1.0"encoding="utf-8"?>
<RelativeLayoutxmlns: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, Button2:在AndroidManifest.xml中的该activity配置 android:windowSoftInputMode="stateHidden|adjustResize"3:看如下代码
[java]view plaincopyprint?
etAccount = (EditText) this.findViewById(R.id.sms_login_et_accout);
etAccount.setOnClickListener(this);
etAccount.setOnTouchListener(new OnTouchListener() {
@Override
publicboolean onTouch(View v, MotionEvent event) {
changeScrollView();
returnfalse;
}
});
/**
* 使ScrollView指向底部
*/
privatevoid changeScrollView(){
h.postDelayed(new Runnable() {
@Override
publicvoid run() {
sl_center.scrollTo(0, sl_center.getHeight());
}
}, 300);
}
Handler h = new Handler(){
publicvoid handleMessage(Message msg) {
};
};
4:具体问题具体分析,方法有多种,欢迎大家讨论。
相关文章推荐
- 【Android】解决软键盘遮挡登陆按钮
- 【Android】解决软键盘遮挡登陆按钮
- Android开发软键盘遮挡登陆按钮的完美解决方案
- android虚拟键盘弹出遮挡登陆按钮问题的解决方法
- android开发软键盘遮挡登陆按钮
- Android优雅的方式解决软键盘遮挡按钮问题
- 解决Android软键盘挡住登录按钮的问题!
- Android 模仿QQ登录界面解决软键盘遮挡问题
- 【Android】4.4以上使用透明状态栏后布局被软键盘遮挡的解决办法
- Android 解决在页面底部置输入框,软键盘遮挡部分输入框的问题
- Android PopupWindow 与 软键盘 的遮挡问题解决
- Android解决软键盘遮挡Button
- android 解决软键盘遮挡popwindow问题
- Android 软键盘遮挡控件的解决办法
- Android软键盘隐藏,遮挡EidtText解决办法
- Android解决被软键盘遮挡的EditText问题
- Android软键盘隐藏,遮挡EidtText解决办法
- Android PopupWindow 与 软键盘 的遮挡问题解决
- 解决软键盘遮挡登录按钮
- Android小技巧 Part II——软键盘遮挡登录按钮