我的應用程序底部有一個編輯文本。我希望在觸摸事件時始終實現該功能,軟鍵盤會將整個窗口滾動到頂部,以便我的EditText保持可見狀態。軟鍵盤和編輯文本的問題
問題是,有時窗口根本不滾動,編輯文本仍然隱藏在軟鍵盤後面。奇怪的是,在那些時刻,如果我按下任何東西或與窗口中的其他元素進行交互,顯然它會刷新或類似的東西,然後它正確地滾動到頂部,讓我看到編輯文本。
我嘗試不同的事情,這是我的最終代碼:
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@android:color/black">
<my.Custom_Edit_Text
android:id="@+id/my_custom_edit_text"
style="@style/my_custom_edit_text_Style"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_centerInParent="true"
android:maxLength="@integer/data_title_max_length"
android:text="@string/my_custom_edit_text_default"
android:selectAllOnFocus="true"
android:focusable="true"
android:focusableInTouchMode="true"
android:cursorVisible="true"
android:inputType="text"/>
這是我的Custom_Edit_Text代碼,在那裏我處理onTouch事件:
setOnTouchListener(new OnTouchListener() {
@Override
public boolean onTouch(View v, MotionEvent event) {
requestFocus();
}
return false;
}
});
我也有在Manifest文件中設置此屬性:
android:windowSoftInputMode="stateHidden|adjustPan"
您是否聽說過觸摸事件發生時活動重疊的權利? – 2013-02-14 10:02:47