"adjustResize"android
The activity's main window is always resized to make room for the soft keyboard on screen. Activity主窗口会缩小本身的显示空间,腾出键盘的位置。
"adjustPan"less
The activity's main window is not resized to make room for the soft keyboard. Rather, the contents of the window are automatically panned so that the current focus is never obscured by the keyboard and users can always see what they are typing. This is generally less desirable than resizing, because the user may need to close the soft keyboard to get at and interact with obscured parts of the window. Activity主窗口不会缩小本身的显示空间,而是会移动内部布局(部分布局被移出界面),使当前焦点不被键盘遮挡,用户能够看到输入内容。 一般都用adjustResize,少用adjustPan,由于用户须要关闭键盘,才能再和被移除的布局进行交互。
没有滚动控件的布局默认属性为adjustPan 有滚动控件的布局默认属性为adjustResize布局
布局文件code
<?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent" android:layout_height="match_parent" android:orientation="vertical" tools:context="com.df.softinputdemo.MainActivity"> <TextView android:layout_width="match_parent" android:layout_height="wrap_content" android:gravity="center" android:text="Hello World!"/> <Button android:layout_width="match_parent" android:layout_height="wrap_content" android:text="Button" /> <ScrollView android:layout_width="match_parent" android:layout_height="match_parent"> <LinearLayout android:layout_width="match_parent" android:layout_height="match_parent" android:orientation="vertical" > <EditText android:layout_width="match_parent" android:layout_height="wrap_content" android:text="1" /> <EditText android:layout_width="match_parent" android:layout_height="wrap_content" android:text="2" /> <EditText android:layout_width="match_parent" android:layout_height="wrap_content" android:text="3" /> <EditText android:layout_width="match_parent" android:layout_height="wrap_content" android:text="4" /> <EditText android:layout_width="match_parent" android:layout_height="wrap_content" android:text="5" /> <EditText android:layout_width="match_parent" android:layout_height="wrap_content" android:text="6" /> <EditText android:layout_width="match_parent" android:layout_height="wrap_content" android:text="7" /> <EditText android:layout_width="match_parent" android:layout_height="wrap_content" android:text="8" /> <EditText android:layout_width="match_parent" android:layout_height="wrap_content" android:text="9" /> <EditText android:layout_width="match_parent" android:layout_height="wrap_content" android:text="10" /> <EditText android:layout_width="match_parent" android:layout_height="wrap_content" android:text="11" /> <EditText android:layout_width="match_parent" android:layout_height="wrap_content" android:text="12" /> <EditText android:layout_width="match_parent" android:layout_height="wrap_content" android:text="13" /> <EditText android:layout_width="match_parent" android:layout_height="wrap_content" android:text="14" /> <EditText android:layout_width="match_parent" android:layout_height="wrap_content" android:text="15" /> </LinearLayout> </ScrollView> </LinearLayout>
截图:第一张为打开界面截图,第二张为点击第10个EditText截图xml
一、没有滚动控件(ScrollView)的布局图片
1)设置为adjustPan
2)设置为adjustResize
二、有滚动控件(ScrollView)的布局utf-8
1)设置为adjustPan
2)设置为adjustResize