我有文本區域和向下的「ok」和「cancel」按鈕。 當我點擊文本區域鍵盤出現,並專注於文本區域和按鈕隱藏在鍵盤後面。android向下滾動
我希望當文本區域焦點滾動一點點,並顯示底部按鈕,而文本區域ID選中。
我有文本區域和向下的「ok」和「cancel」按鈕。 當我點擊文本區域鍵盤出現,並專注於文本區域和按鈕隱藏在鍵盤後面。android向下滾動
我希望當文本區域焦點滾動一點點,並顯示底部按鈕,而文本區域ID選中。
我固定它通過自己:d以下是代碼
我稱爲以下的方法時文本框獲得焦點
private final void focusOnButtons(){
new Handler().postDelayed(new Runnable() {
@Override
public void run() {
ScrollView sv = (ScrollView)findViewById(R.id.scrl);
sv.scrollTo(0, sv.getBottom());
}
},1000);
}
你可以嘗試在滾動型包裝現有的佈局:
https://developer.android.com/reference/android/widget/ScrollView.html
您的佈局xml文件可能類似於:
<?xml version="1.0" encoding="utf-8"?>
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/ScrollView01" android:layout_width="wrap_content"
android:layout_height="wrap_content">
<LinearLayout
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<EditText android:text="@string/hello" android:id="@+id/EditText01"
android:layout_width="wrap_content" android:layout_height="wrap_content">
</EditText>
<LinearLayout
android:orientation="horizontal"
android:layout_width="fill_parent"
android:layout_height="wrap_content">
<Button android:text="@+id/Button01" android:id="@+id/Button01"
android:layout_width="wrap_content" android:layout_height="wrap_content">
</Button>
<Button android:text="@+id/Button02" android:id="@+id/Button02"
android:layout_width="wrap_content" android:layout_height="wrap_content">
</Button>
</LinearLayout>
</LinearLayout>
</ScrollView>
評論迴應:
你可能想看看這個頁面:
https://developer.android.com/training/keyboard-input/index.html
我想你想要的結果可以通過移動滾動查看外的按鈕並在活動上設置android:windowSoftInputMode="adjustResize"
來完成。
我會從溶液調整幾件事情:
1 .-把smoothScroll代替硬盤滾動
2.-將延遲從1000減少到300(足夠)
OnFocusChangeListener onFocus = new OnFocusChangeListener() {
@Override
public void onFocusChange(View v, boolean hasFocus) {
new Handler().postDelayed(new Runnable() {
@Override
public void run() {
scrollView.smoothScrollTo(0, scrollView.getBottom());
}
},300);
}
};
我已經使用了滾動視圖,但是當出現鍵盤時它不滾動到顯示按鈕。 – 2010-04-20 11:27:49