2011-08-04 159 views
0

在我的一個課程中,我在屏幕底部有兩個EditText和一個Button。當我選擇其中一個EditText時,出現鍵盤。問題是,然後EditTextButton被移動到屏幕的前面,以便看到你正在寫什麼。但是,在EditText之上,我有兩個TextView,當我給EditText寫信時,TextView從屏幕上消失。鍵盤android事件?

我可以這樣做:當用戶在Edittext中寫入內容時,只有EditText上移,其餘不受影響?

+0

可以使用setOnFocusChangeListener與此佈局參數... – Hanry

+0

你能不能給我一個例子嗎? – Gabrielle

+0

你想在編輯過程中將editText帶到屏幕的中心? – Hanry

回答

0

此代碼動畫您edtxt從上到下:

DO相應改變:

edtxt.setOnFocusChangeListener(new OnFocusChangeListener() { 
@Override 
public void onFocusChange(View v, boolean hasFocus) { 
if(hasFocus) 
{ 
TranslateAnimation slide = new TranslateAnimation(0, 0, -100,0); 
    slide.setDuration(1000); 
    slide.setFillAfter(true); 
    edtxt.startAnimation(slide); 
} 

} 
    }); 
0

添加android:windowSoftInputMode屬性您ActivityAndroidManifest

<activity android:name=".MyActivity" 
      android:label="@string/app_name" 
      android:windowSoftInputMode="adjustPan"> 
</activity> 

這將導致當軟件鍵盤打開時,屏幕可以正確調整。

0

可以overrite onConfigurationChanged方法和檢查鍵盤上/下狀態

@Override 
public void onConfigurationChanged(Configuration config) 
{ 
    super.onConfigurationChanged(config); 


    if (newConfig.hardKeyboardHidden == Configuration.HARDKEYBOARDHIDDEN_NO) 
    { 

    } 
    else if (newConfig.hardKeyboardHidden == Configuration.HARDKEYBOARDHIDDEN_YES) 
    { 

    } 
} 

<activity android:name=".MyActivity" 
      android:configChanges="orientation|keyboardHidden" 
      android:label="@string/app_name">