Android開(kāi)發(fā)軟鍵盤遮擋登陸按鈕的完美解決方案
在應(yīng)用登陸頁(yè)面我們需要填寫用戶名和密碼。當(dāng)填寫這些信息的時(shí)候,軟鍵盤會(huì)遮擋登陸按鈕,這使得用戶體驗(yàn)較差,所以今天就來(lái)解決這個(gè)問(wèn)題
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="請(qǐng)輸入賬號(hào)" 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="請(qǐng)輸入密碼" 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:層級(jí)關(guān)系
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開(kāi)發(fā)軟鍵盤遮擋登陸按鈕的完美解決方案,希望對(duì)大家有所幫助,如果大家有任何疑問(wèn)請(qǐng)給我留言,小編會(huì)及時(shí)回復(fù)大家的。在此也非常感謝大家對(duì)腳本之家網(wǎng)站的支持!
相關(guān)文章
Android實(shí)現(xiàn)圖片預(yù)覽與保存功能
在App開(kāi)發(fā)中,通常為了省流提高加載速度提升用戶體驗(yàn)我們通常在列表中或新聞中的插圖都是以縮略圖壓縮過(guò)的圖片來(lái)進(jìn)行展示,當(dāng)用戶點(diǎn)擊圖片時(shí)我們?cè)偃ゼ虞d真正像素的大圖讓用戶預(yù)覽。本文將利用Flutter實(shí)現(xiàn)這一功能,需要的可以參考一下2022-04-04Android View教程之自定義驗(yàn)證碼輸入框效果
這篇文章主要給大家介紹了關(guān)于Android View教程之自定義驗(yàn)證碼輸入框效果的相關(guān)資料,文中通過(guò)示例代碼介紹的非常詳細(xì),對(duì)各位Android開(kāi)發(fā)者們具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面來(lái)一起學(xué)習(xí)學(xué)習(xí)吧2019-05-05基于Android中獲取資源的id和url方法總結(jié)
下面小編就為大家分享一篇基于Android中獲取資源的id和url方法總結(jié),具有很好的參考價(jià)值,希望對(duì)大家有所幫助。一起跟隨小編過(guò)來(lái)看看吧2018-02-02Android實(shí)現(xiàn)Service獲取當(dāng)前位置(GPS+基站)的方法
這篇文章主要介紹了Android實(shí)現(xiàn)Service獲取當(dāng)前位置(GPS+基站)的方法,較為詳細(xì)的分析了Service基于GPS位置的技巧,具有一定參考借鑒價(jià)值,需要的朋友可以參考下2015-09-09Android開(kāi)發(fā)實(shí)現(xiàn)圓形圖片功能示例
這篇文章主要介紹了Android開(kāi)發(fā)實(shí)現(xiàn)圓形圖片功能,涉及Android實(shí)現(xiàn)圓形圖片的界面布局與CirImageView組件相關(guān)使用操作技巧,需要的朋友可以參考下2019-04-04Android實(shí)現(xiàn)帶圖標(biāo)的列表對(duì)話框
這篇文章主要為大家詳細(xì)介紹了Android實(shí)現(xiàn)帶圖標(biāo)的列表對(duì)話框,具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下2017-12-12在Android系統(tǒng)中使用gzip進(jìn)行數(shù)據(jù)傳遞實(shí)例代碼
HTTP協(xié)議上的GZIP編碼是一種用來(lái)改進(jìn)WEB應(yīng)用程序性能的技術(shù),4.4MB的文本數(shù)據(jù)經(jīng)過(guò)Gzip傳輸?shù)娇蛻舳酥笞優(yōu)?92KB,壓縮效率極高,下面與大家分享下具體的實(shí)現(xiàn)2013-06-06Android ViewPager制作新手導(dǎo)航頁(yè)(動(dòng)態(tài)加載)
這篇文章主要為大家詳細(xì)介紹了Android ViewPager制作新手導(dǎo)航頁(yè),了解什么是動(dòng)態(tài)加載指示器,感興趣的小伙伴們可以參考一下2016-05-05Android原生側(cè)滑控件DrawerLayout使用方法詳解
這篇文章主要為大家詳細(xì)介紹了Android原生側(cè)滑控件DrawerLayout的使用方法,具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下2017-12-12