2013-02-14 94 views
0

我的應用程序底部有一個編輯文本。我希望在觸摸事件時始終實現該功能,軟鍵盤會將整個窗口滾動到頂部,以便我的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" 
+0

您是否聽說過觸摸事件發生時活動重疊的權利? – 2013-02-14 10:02:47

回答

1

使用本

android:configChanges="keyboardHidden|orientation" 

android:windowSoftInputMode="adjustPan" 

讓我知道同時使用這對您有所幫助或不與同樣在虛擬鍵盤產生的問題,也幫助佈局使用滾動視圖位

把你的整個佈局其在滾動視圖distroting

+0

我的應用程序僅限於人像模式,所以隱藏旋轉鍵盤不會幫助我。我已經使用了adjustPan配置,並試圖將所有內容放在滾動視圖中(我忘了在我的問題中提到遺憾)。我發現了一個使用TextView的解決方案。但是,無論如何謝謝你的提示,它們非常有用。 – Eduardo 2013-02-14 10:17:45