在我的一個課程中,我在屏幕底部有兩個EditText
和一個Button
。當我選擇其中一個EditText
時,出現鍵盤。問題是,然後EditText
和Button
被移動到屏幕的前面,以便看到你正在寫什麼。但是,在EditText
之上,我有兩個TextView
,當我給EditText
寫信時,TextView
從屏幕上消失。鍵盤android事件?
我可以這樣做:當用戶在Edittext
中寫入內容時,只有EditText
上移,其餘不受影響?
在我的一個課程中,我在屏幕底部有兩個EditText
和一個Button
。當我選擇其中一個EditText
時,出現鍵盤。問題是,然後EditText
和Button
被移動到屏幕的前面,以便看到你正在寫什麼。但是,在EditText
之上,我有兩個TextView
,當我給EditText
寫信時,TextView
從屏幕上消失。鍵盤android事件?
我可以這樣做:當用戶在Edittext
中寫入內容時,只有EditText
上移,其餘不受影響?
此代碼動畫您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);
}
}
});
添加android:windowSoftInputMode
屬性您Activity
在AndroidManifest
:
<activity android:name=".MyActivity"
android:label="@string/app_name"
android:windowSoftInputMode="adjustPan">
</activity>
這將導致當軟件鍵盤打開時,屏幕可以正確調整。
可以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">
可以使用setOnFocusChangeListener與此佈局參數... – Hanry
你能不能給我一個例子嗎? – Gabrielle
你想在編輯過程中將editText帶到屏幕的中心? – Hanry