Android應(yīng)用中出現(xiàn)軟鍵盤(pán)遮擋住按鈕如何解決?相信很多沒(méi)有經(jīng)驗(yàn)的人對(duì)此束手無(wú)策,為此本文總結(jié)了問(wèn)題出現(xiàn)的原因和解決方法,通過(guò)這篇文章希望你能解決這個(gè)問(wèn)題。
成都創(chuàng)新互聯(lián)公司專注為客戶提供全方位的互聯(lián)網(wǎng)綜合服務(wù),包含不限于成都做網(wǎng)站、網(wǎng)站設(shè)計(jì)、外貿(mào)營(yíng)銷網(wǎng)站建設(shè)、青山網(wǎng)絡(luò)推廣、微信小程序定制開(kāi)發(fā)、青山網(wǎng)絡(luò)營(yíng)銷、青山企業(yè)策劃、青山品牌公關(guān)、搜索引擎seo、人物專訪、企業(yè)宣傳片、企業(yè)代運(yùn)營(yíng)等,從售前售中售后,我們都將竭誠(chéng)為您服務(wù),您的肯定,是我們最大的嘉獎(jiǎng);成都創(chuàng)新互聯(lián)公司為所有大學(xué)生創(chuàng)業(yè)者提供青山建站搭建服務(wù),24小時(shí)服務(wù)熱線:028-86922220,官方網(wǎng)址:www.cdcxhl.com
如圖:
實(shí)現(xiàn)1
xml
java
mScrollView=(ScrollView)view.findViewById(R.id.scrollview); usernamelogin_username.setOnTouchListener(newView.OnTouchListener(){ @Override publicbooleanonTouch(Viewv,MotionEventevent){ changeScrollView(); returnfalse; } }); usernamelogin_password.setOnTouchListener(newView.OnTouchListener(){ @Override publicbooleanonTouch(Viewv,MotionEventevent){ changeScrollView(); returnfalse; } });
/** *使ScrollView指向底部 */ privatevoidchangeScrollView(){ newHandler().postDelayed(newRunnable(){ @Override publicvoidrun(){ mScrollView.scrollTo(0,mScrollView.getHeight()); } },300); }
實(shí)現(xiàn)2
xml同上
anim下新建gone.xml
<?xml version="1.0" encoding="utf-8"?>
visiable.xml
<?xml version="1.0" encoding="utf-8"?>
或者直接在代碼中
importandroid.os.Bundle; importandroid.os.Handler; importandroid.support.v7.app.AppCompatActivity; importandroid.view.KeyEvent; importandroid.view.MotionEvent; importandroid.view.View; importandroid.view.animation.Animation; importandroid.view.animation.AnimationSet; importandroid.view.animation.ScaleAnimation; importandroid.widget.Button; importandroid.widget.EditText; importandroid.widget.ImageView; publicclassMainActivityextendsAppCompatActivity{ privateImageViewmHead;//頭部ImageView @Override protectedvoidonCreate(BundlesavedInstanceState){ super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); mHead=(ImageView)findViewById(R.id.iv_head); finalButtonbtn=(Button)findViewById(R.id.btn_usernamelogin_dologin); finalEditTextet_pass=(EditText)findViewById(R.id.et_usernamelogin_password); finalEditTextet_name=(EditText)findViewById(R.id.et_usernamelogin_username); /** *當(dāng)輸入被點(diǎn)擊 */ et_name.setOnTouchListener(newView.OnTouchListener(){ @Override publicbooleanonTouch(Viewv,MotionEventevent){ start(); returnfalse; } }); btn.setEnabled(false); btn.setOnClickListener(newView.OnClickListener(){ @Override publicvoidonClick(Viewv){ } }); } privatevoidstart(){ AnimationSetanimationSet=newAnimationSet(true); ScaleAnimationscaleAnimation=newScaleAnimation( 1,0.1f,1,0.1f, Animation.RELATIVE_TO_SELF,0.5f, Animation.RELATIVE_TO_SELF,0.5f); scaleAnimation.setDuration(500); animationSet.addAnimation(scaleAnimation); animationSet.setFillAfter(true); animationSet.setFillBefore(false); animationSet.setRepeatCount(0);//設(shè)置重復(fù)次數(shù) mHead.startAnimation(scaleAnimation); newHandler().postDelayed(newRunnable(){ @Override publicvoidrun(){ mHead.setVisibility(View.GONE); } },500); } /** *菜單、返回鍵響應(yīng) */ @Override publicbooleanonKeyDown(intkeyCode,KeyEventevent){ //TODOAuto-generatedmethodstub if(keyCode==KeyEvent.KEYCODE_BACK){ if(mHead.getVisibility()==View.GONE){ AnimationSetanimationSet=newAnimationSet(true); ScaleAnimationscaleAnimation=newScaleAnimation( 0.1f,1f,0.1f,1f, Animation.RELATIVE_TO_SELF,0.5f, Animation.RELATIVE_TO_SELF,0.5f); scaleAnimation.setDuration(500); animationSet.addAnimation(scaleAnimation); animationSet.setFillAfter(true); animationSet.setFillBefore(false); mHead.startAnimation(scaleAnimation); mHead.setVisibility(View.VISIBLE); }else{ finish(); } } returnfalse; } }
效果呢:
看完上述內(nèi)容,你們掌握Android應(yīng)用中出現(xiàn)軟鍵盤(pán)遮擋住按鈕如何解決的方法了嗎?如果還想學(xué)到更多技能或想了解更多相關(guān)內(nèi)容,歡迎關(guān)注創(chuàng)新互聯(lián)行業(yè)資訊頻道,感謝各位的閱讀!