不幸的是,在當前的SDK中,當軟鍵盤顯示並消失時,我們對系統的仁慈程度有點不解。實現您正在查找的行爲的最佳方法是在窗口中保留默認輸入模式,並確保您的視圖中有一個可滾動元素。請記住,當隱藏鍵盤(內容小於滾動視圖)時,此元素不需要滾動,但當鍵盤顯示時,它將摺疊可滾動視圖的大小並保留其他所有內容。
下面是一個例子。比方說,這是你的RES /佈局/ main.xml中:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<LinearLayout
android:id="@+id/control"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:orientation="vertical">
<EditText
android:layout_width="fill_parent"
android:layout_height="wrap_content"/>
<Button
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="A Button"/>
</LinearLayout>
<ScrollView
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_above="@id/control">
</ScrollView>
</RelativeLayout>
試試這個爲基本活動的根佈局,你會看到整個LinearLayout
上下滑動的鍵盤,因爲Android是調整ScrollView
的視口,而不是向上滑動視圖JUST足以顯示焦點輸入元素(您現在看到的)。
不知道我是否正確理解了這種情況,但是無法將圖像設置爲根佈局背景資源,並且不必擔心其調整大小,而其餘佈局可以通過鍵盤上下移動? – ANemati 2017-01-12 21:40:37