相應用過Android手機的朋友都知道,有時候在文字框中輸入文字後,操作按鈕被IME遮擋了,不得不關閉IME才可以繼續操作。
比如下面這個畫面:
畫面布局:
<?xml version="1.0" encoding="utf-8"?><br /><LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"<br />android:id="@+id/ll2" android:orientation="vertical"<br />android:layout_width="fill_parent" android:layout_height="fill_parent"><br /><CheckBox android:id="@+id/widget57" android:layout_width="wrap_content"<br />android:layout_height="wrap_content" android:text="@string/location"<br />android:layout_gravity="right"><br /></CheckBox><br /><EditText android:id="@+id/widget34" android:layout_width="fill_parent"<br />android:layout_height="fill_parent" android:layout_weight="1"<br />android:textColorHighlight="#cccccc" android:hint="你想說什嗎?"<br />android:gravity="top" android:textSize="18sp"><br /></EditText><br /><Button android:id="@+id/widget53" android:layout_width="100px"<br />android:layout_height="wrap_content" android:text="@string/share"<br />android:layout_gravity="right"/><br /></LinearLayout><br />
如果不做任何操作,那麼點擊文字框後的效果肯定是:
此時,【共用】按鈕被IME擋住了,必須關閉IME才可以操作了。
有的朋友會說,可以在布局外面再加一個ScrollView,這樣的畫,UI布局就和IME分離了,IME出現後,上面還可以滾動。
但是這樣的效果好嗎? 我們來看一下效果(布局外加ScrollView的效果):
畫面布局:
<?xml version="1.0" encoding="utf-8"?><br /><ScrollView xmlns:android="http://schemas.android.com/apk/res/android"<br />android:layout_width="fill_parent" android:layout_height="fill_parent"<br />android:orientation="vertical"><br /><LinearLayout<br />android:id="@+id/ll2" android:orientation="vertical"<br />android:layout_width="fill_parent" android:layout_height="fill_parent"><br /><CheckBox android:id="@+id/widget57" android:layout_width="wrap_content"<br />android:layout_height="wrap_content" android:text="@string/location"<br />android:layout_gravity="right"><br /></CheckBox><br /><EditText android:id="@+id/widget34" android:layout_width="fill_parent"<br />android:layout_height="400px" android:layout_weight="1"<br />android:textColorHighlight="#cccccc" android:hint="你想說什嗎?"<br />android:gravity="top" android:textSize="18sp"><br /></EditText><br /><Button android:id="@+id/widget53" android:layout_width="100px"<br />android:layout_height="wrap_content" android:text="@string/share"<br />android:layout_gravity="right"/><br /></LinearLayout><br /></ScrollView>
可以看出,上面部分右側有一個捲軸,使用者可以通過從下滾動來點擊按鈕。但是個人覺得,這樣還不如直接關閉IME來點擊按鈕來的方便!
那麼有沒有更好的辦法呢? 答案是有!
先看一下這個更好的方法是什麼效果:
可以看出,UI布局也與IME分離了,同時EditText地區自動縮小了。這樣的話,即不影響使用者輸入,也不影響使用者進一步操作!
而且即使開啟了IME,使用者也可以看到UI全貌,感覺比較舒服、友好。
下面就說一下,這個效果是如何做到的.
其實答案很簡單,不需要更改局部檔案,而是修改AndroidManifest.xml檔案,在Activity屬性中加一條:
android:windowSoftInputMode="adjustResize"
AndroidManifest.xml修改前後比較:
該屬性還有一些其他值,大家可以上網查一下。 (這邊給個連結: http://blog.csdn.net/liluo1217/archive/2011/02/14/6184169.aspx)