android 软键盘遮住按钮,Android应用中出现软键盘遮挡住按钮如何解决
Android應用中出現軟鍵盤遮擋住按鈕如何解決
發布時間:2020-11-20 16:25:47
來源:億速云
閱讀:110
作者:Leah
Android應用中出現軟鍵盤遮擋住按鈕如何解決?相信很多沒有經驗的人對此束手無策,為此本文總結了問題出現的原因和解決方法,通過這篇文章希望你能解決這個問題。
如圖:
實現1
xml
android:id="@+id/scrollview"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:fadingEdge="none"
android:scrollbars="none">
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
android:layout_width="100dp"
android:layout_height="100dp"
android:layout_gravity="center_horizontal"
android:layout_marginTop="20dp"
android:src="@mipmap/ic_loginhead"/>
android:id="@+id/et_usernamelogin_username"
android:layout_width="match_parent"
android:layout_height="40dp"
android:layout_marginTop="10dp"
android:background="@null"
android:hint="請輸入已驗證手機"
android:inputType="number"
android:lines="1"
android:maxLength="11"/>
android:layout_width="match_parent"
android:layout_height="2px"
android:layout_marginLeft="50dp"
android:layout_marginRight="50dp"
android:background="@color/pating_line"/>
android:id="@+id/et_usernamelogin_password"
android:layout_width="match_parent"
android:layout_height="40dp"
android:layout_marginTop="20dp"
android:background="@null"
android:digits="0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ_?"
android:hint="請輸入密碼"
android:inputType="textPassword"/>
android:layout_width="match_parent"
android:layout_height="2px"
android:layout_marginLeft="50dp"
android:layout_marginRight="50dp"
android:background="@color/pating_line"/>
android:id="@+id/btn_usernamelogin_dologin"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
android:layout_marginLeft="50dp"
android:layout_marginRight="50dp"
android:layout_marginTop="30dp"
android:background="@drawable/btn_selecter"
android:enabled="false"
android:text="登錄"
android:textColor="@color/white"
/>
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);
}
實現2
xml同上
anim下新建gone.xml
android:fromXScale="1.0"
android:toXScale="0.0"
android:fromYScale="1.0"
android:toYScale="0.0"
android:pivotX="50%"
android:pivotY="50%"
android:duration="500"
android:repeatCount="0"/>
visiable.xml
android:fromXScale="0.0"
android:toXScale="1.0"
android:fromYScale="0.0"
android:toYScale="1.0"
android:pivotX="50%"
android:pivotY="50%"
android:duration="500"
android:repeatCount="0"/>
或者直接在代碼中
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);
/**
*當輸入被點擊
*/
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);//設置重復次數
mHead.startAnimation(scaleAnimation);
newHandler().postDelayed(newRunnable(){
@Override
publicvoidrun(){
mHead.setVisibility(View.GONE);
}
},500);
}
/**
*菜單、返回鍵響應
*/
@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;
}
}
效果呢:
看完上述內容,你們掌握Android應用中出現軟鍵盤遮擋住按鈕如何解決的方法了嗎?如果還想學到更多技能或想了解更多相關內容,歡迎關注億速云行業資訊頻道,感謝各位的閱讀!
總結
以上是生活随笔為你收集整理的android 软键盘遮住按钮,Android应用中出现软键盘遮挡住按钮如何解决的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 小数分数转换c语言,这是把小数转换成分数
- 下一篇: android sina oauth2.