不幸的是,在当前的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