欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

Android優(yōu)雅的方式解決軟鍵盤遮擋按鈕問題

 更新時間:2017年01月22日 15:40:33   作者:吻中求勝  
這篇文章主要介紹了Android優(yōu)雅的方式解決軟鍵盤遮擋按鈕問題,非常不錯,具有參考借鑒價值,需要的朋友可以參考下

前言

比如在進行登錄的操作中,用戶輸入完密碼之后,肯定是想直接點擊登錄按鈕的。返回鍵隱藏軟鍵盤這樣的體驗肯定很糟糕,程序員,遇到問題解決問題。

實現(xiàn)1

xml

<ScrollView
android:id="@+id/scrollview"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:fadingEdge="none"
android:scrollbars="none">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
<ImageView
android:layout_width="100dp"
android:layout_height="100dp"
android:layout_gravity="center_horizontal"
android:layout_marginTop="20dp"
android:src="@mipmap/ic_loginhead"/>
<EditText
android:id="@+id/et_usernamelogin_username"
style="@style/customEditText"
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"/>
<ImageView
android:layout_width="match_parent"
android:layout_height="2px"
android:layout_marginLeft="50dp"
android:layout_marginRight="50dp"
android:background="@color/pating_line"/>
<EditText
android:id="@+id/et_usernamelogin_password"
style="@style/customEditText"
android:layout_width="match_parent"
android:layout_height="40dp"
android:layout_marginTop="20dp"
android:background="@null"
android:digits="0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ_?"
android:hint="請輸入密碼"
android:inputType="textPassword"/>
<ImageView
android:layout_width="match_parent"
android:layout_height="2px"
android:layout_marginLeft="50dp"
android:layout_marginRight="50dp"
android:background="@color/pating_line"/>
<Button
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"
/>
</LinearLayout>
</ScrollView>

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);
 }

實現(xiàn)2

xml同上

anim下新建gone.xml

<?xml version="1.0" encoding="utf-8"?>
<scale xmlns:android="http://schemas.android.com/apk/res/android"  
 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

<?xml version="1.0" encoding="utf-8"?>
 <scale xmlns:android="http://schemas.android.com/apk/res/android" 
 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);//設置重復次數(shù)
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優(yōu)雅的方式解決軟鍵盤遮擋按鈕問題,希望對大家有所幫助,如果大家有任何疑問請給我留言,小編會及時回復大家的。在此也非常感謝大家對腳本之家網(wǎng)站的支持!

相關文章

  • Android中的Launch Mode詳情

    Android中的Launch Mode詳情

    這篇文章主要介紹了Android中的Launch Mode詳情,文章圍繞主題的相關資料展開詳細的內(nèi)容介紹,具有一定的參考價值,需要的小伙伴可以參考一下
    2022-06-06
  • Flutter實現(xiàn)PopupMenu彈出式菜單按鈕詳解

    Flutter實現(xiàn)PopupMenu彈出式菜單按鈕詳解

    這篇文章主要介紹了Flutter實現(xiàn)PopupMenu彈出式菜單按鈕,PopupMenuButton是一個用于創(chuàng)建彈出菜單的小部件,當用戶點擊觸發(fā)按鈕時,PopupMenuButton會在屏幕上方或下方彈出一個菜單,感興趣想要詳細了解可以參考下文
    2023-05-05
  • Android創(chuàng)建與解析XML(二)——詳解Dom方式

    Android創(chuàng)建與解析XML(二)——詳解Dom方式

    本篇文章主要介紹了Android創(chuàng)建與解析XML(二)——詳解Dom方式 ,這里整理了詳細的代碼,有需要的小伙伴可以參考下。
    2016-11-11
  • Flutter應用集成極光推送的實現(xiàn)示例

    Flutter應用集成極光推送的實現(xiàn)示例

    這篇文章主要介紹了Flutter應用集成極光推送的實現(xiàn)示例,文中通過示例代碼介紹的非常詳細,對大家的學習或者工作具有一定的參考學習價值,需要的朋友們下面隨著小編來一起學習學習吧
    2020-02-02
  • Android的App啟動時白屏的問題解決辦法

    Android的App啟動時白屏的問題解決辦法

    這篇文章主要介紹了Android的App啟動時白屏的問題相關資料,在App啟動的第一次的時候白屏會一段時間,這里提供了解決辦法,需要的朋友可以參考下
    2017-08-08
  • Android Studio實現(xiàn)QQ的注冊登錄和好友列表跳轉(zhuǎn)

    Android Studio實現(xiàn)QQ的注冊登錄和好友列表跳轉(zhuǎn)

    最近做了一個項目,這篇文章主要介紹了Android Studio界面跳轉(zhuǎn),本次項目主要包含了注冊、登錄和好友列表三個界面以及之間相互跳轉(zhuǎn),感興趣的可以了解一下
    2021-05-05
  • Android中檢查、設置默認程序詳解

    Android中檢查、設置默認程序詳解

    這篇文章主要介紹了Android中檢查、設置默認程序詳解,本文講解了檢測是否有默認的程序、如果有默認程序、沒有默認的程序的情況等內(nèi)容,需要的朋友可以參考下
    2015-01-01
  • android保存Bitmap圖片到指定文件夾示例

    android保存Bitmap圖片到指定文件夾示例

    android把Bitmap圖片保存到指定文件夾中,具體實現(xiàn)方法如下,感興趣的朋友可以參考下哈,希望對大家有所幫助
    2013-06-06
  • Android LayoutInflater中 Inflate()方法應用

    Android LayoutInflater中 Inflate()方法應用

    本文主要介紹Android 中Inflate 方法的用法, 在開發(fā)Android應用過程中,可以在程序中應用 Inflate()方法加載新布局,希望能幫助有需要的朋友
    2016-07-07
  • Android倒計時神器(CountDownTimer)

    Android倒計時神器(CountDownTimer)

    這篇文章主要為大家詳細介紹了Android倒計時神器CountDownTimer,文中示例代碼介紹的非常詳細,具有一定的參考價值,感興趣的小伙伴們可以參考一下
    2020-01-01

最新評論