當在Android的layout設計里面如果輸入框過多,則在輸入彈出軟鍵盤的時候,下面的輸入框會有一部分被軟件盤擋住,從而不能獲取焦點輸入。
下面提供三種解決辦法:
方法一:在你的activity中的oncreate中setContentView之前寫上這個代碼getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_ADJUST_PAN);
方法二:在 項目的AndroidManifest.xml文件中界面對應的<activity>里加入 android:windowSoftInputMode="stateVisible|adjustResize",這樣會讓屏幕整體上移。如果加上的 是 android:windowSoftInputMode="adjustPan"這樣鍵盤就會覆蓋屏幕。
方法三:把頂級的layout替換成ScrollView,或者說在頂級的Layout上面再加一層ScrollView的封裝。這樣就會把軟鍵盤和輸入框一起滾動了,軟鍵盤會一直處於底部。
在我們的LinearLayout布局外添加ScrollView
方法三示例:
由原來的:
1
2
3
4
5
6
7
8
|
<?xml version=
"1.0"
encoding=
"utf-8"
?>
<LinearLayout xmlns:android=
"http://schemas.android.com/apk/res/android"
android:layout_width=
"fill_parent"
android:layout_height=
"fill_parent"
>
......
</LinearLayout>
|
改為:
1
2
3
4
5
6
7
8
9
10
11
12
13
|
<?xml version=
"1.0"
encoding=
"utf-8"
?>
<ScrollView xmlns:android=
"http://schemas.android.com/apk/res/android"
android:orientation=
"vertical"
android:layout_width=
"fill_parent"
android:layout_height=
"fill_parent"
>
<LinearLayout xmlns:android=
"http://schemas.android.com/apk/res/android"
android:layout_width=
"fill_parent"
android:layout_height=
"fill_parent"
>
......
</LinearLayout>
</ScrollView>
|