問題標題可能會引起誤解,但我認爲這是Android新手常見的問題:我有一個LinearLayout
的活動,並且我有一個EditText
在底部屏幕。當我點擊它時,鍵盤出現在EditText
上,在鍵入時隱藏它。有沒有一種方法可以實現大多數用戶期望的功能,即活動會向下滾動直至EditText
再次變爲可見?EditText被點擊時被鍵盤擋住了
回答
您可以使用ScrollView
作爲頂視圖。並在那裏定義RelativeLayout
。
定義等作爲
<Scrollview.......>
<RelativeLayout .....>
//other view.
</RelativeLayout >
</Scrollview>
@shridutt kothari我舉了一個例子,他如何將這個應用到他的問題中。 – 2013-02-10 17:32:08
您可以使用ScrollView
來實現此目的。
更新:是AVD *這*可怕嗎?我重新啓動了應用程序,現在它的行爲完全符合它的要求。 – whatyouhide 2013-02-10 17:13:04
@whatyouhide AVDs一般是可怕的;) – Ahmad 2013-02-10 17:15:45
添加您LinearLayout
爲Scrollview
當EditText
視圖獲取集中,manually scroll
的ScrollView
的內容。 就是這樣。
您是否曾嘗試將android:windowSoftInputMode="stateVisible|adjustResize"
添加到清單中的活動中?
如果adjustResize仍然無法完全顯示您所期望的視圖,那麼您可以嘗試此操作。無論查看您的關注做出onTouchListener然後做到這一點:
setOnTouchListener(new OnTouchListener() {
Runnable shifter=new Runnable(){
public void run(){
try {
int[] loc = new int[2];
//get the location of someview which gets stored in loc array
findViewById(R.id.someview).getLocationInWindow(loc);
//shift so user can see someview
myscrollView.scrollTo(loc[0], loc[1]);
}
catch (Exception e) {
e.printStackTrace();
}
}}
};
Rect scrollBounds = new Rect();
View divider=findViewById(R.id.someview);
myscollView.getHitRect(scrollBounds);
if (!divider.getLocalVisibleRect(scrollBounds)) {
// the divider view is NOT within the visible scroll window thus we need to scroll a bit.
myscollView.postDelayed(shifter, 500);
}
});
//實際上我們做一個可運行的是滾動到要在屏幕上看到一些視圖的新位置。只有當它不在滾動視圖範圍內時(它不在屏幕上),才能執行該可運行。這樣它將scrollview移動到引用的視圖(在我的情況下,'someview'是一個分隔線)。
最簡單的方法是將android:windowSoftInputMode="adjustPan"
添加到清單中的目標活動。
- 1. EditText隱藏在鍵盤上時點擊
- 2. 在點擊鍵盤(虛擬鍵盤)時替換editText的文本
- 3. 被ActiveRecord控制器擋住的錯誤
- 4. emptyView爲的CollectionView就不會被擋住
- 5. 點擊EditText不會顯示鍵盤?
- 6. 當點擊editText顯示android鍵盤
- 7. 點擊EditText不顯示軟鍵盤
- 8. 底部視圖被頂視圖擋住了
- 9. 被CSS,報告查看器和Div計算擋住了
- 10. 當頁面上的按鈕被點擊時,鍵盤自動被解除
- 11. 隱藏鍵盤按鈕被點擊時xamarin形式
- 12. 當鍵盤被隱藏時,ListView不會更新按鈕點擊
- 13. end當返回按鈕被點擊時鍵盤的編輯
- 14. JavaScript來檢測哪個鍵盤按鍵被點擊
- 15. 單擊EditText時鍵盤不顯示
- 16. 單擊EditText時如何禁用鍵盤?
- 17. pyaudio和pynput:鍵盤被按下/按住時錄音
- 18. 當android:gravity =「center」隱藏時,EditText被鍵盤隱藏 - Android
- 19. (tablayout)當editText被聚焦時,標籤在鍵盤上方出現
- 20. Android自定義ListView - 當軟鍵盤隱藏時Edittext被清除
- 21. 行被點擊時
- 22. Bootstrap 2 Modal部分被軟鍵盤阻擋
- 23. 擋住了FileNotFound異常
- 24. EditText失去焦點時關閉鍵盤
- 25. Android Edittext在鍵盤上輸入的時候失去了重點
- 26. 鍵盤卡住,同時點擊textField從DatePickerDialog獲取日期
- 27. 軟鍵盤打開然後在點擊edittext時關閉
- 28. 如何在editText外部點擊時隱藏鍵盤?
- 29. 在android中點擊EditText之外的時候關閉鍵盤
- 30. 我的Javascript被卡住了
可能的重複http://stackoverflow.com/questions/6411267/softkeyboard-blocking-edittext – Pragnani 2013-02-10 17:13:50