android中的adjustResize和adjustPan之间的区别?

我试图编写一个代码,用于在出现软键盘时重新调整UI组件的大小。 当我使用adjustResize时,它调整了UI组件的大小,同时adjustPan给了我相同的输出。 我想知道它们之间的区别以及何时使用每个组件? 哪一个(adjustPan或adjustResize)适合调整UI的大小?

这是我的xml:

<ScrollView xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent" android:layout_height="match_parent" android:fillViewport="true" > <RelativeLayout android:layout_width="fill_parent" android:layout_height="wrap_content" > <LinearLayout android:layout_width="fill_parent" android:layout_height="wrap_content" android:layout_alignParentBottom="true" android:orientation="vertical" > <EditText android:id="@+id/editText5" android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_marginTop="45dp" android:ems="10" android:inputType="textPersonName" /> <Button android:id="@+id/button1" android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_marginBottom="40dp" android:text="My Button" /> </LinearLayout> </RelativeLayout> </ScrollView> 

和清单文件:

 <?xml version="1.0" encoding="utf-8"?> <manifest xmlns:android="http://schemas.android.com/apk/res/android" package="com.example.adjustscroll" android:versionCode="1" android:versionName="1.0" > <uses-sdk android:minSdkVersion="8" android:targetSdkVersion="17" /> <application android:allowBackup="true" android:icon="@drawable/ic_launcher" android:label="@string/app_name" android:theme="@style/AppTheme" > <activity android:name="com.example.adjustscroll.MainActivity" android:label="@string/app_name" android:windowSoftInputMode="adjustPan|adjustResize" > <intent-filter> <action android:name="android.intent.action.MAIN" /> <category android:name="android.intent.category.LAUNCHER" /> </intent-filter> </activity> </application> </manifest> 

从Android开发者网站链接

“adjustResize”

总是调整活动的主窗口,为屏幕上的软键盘腾出空间。

“adjustPan”

该活动的主窗口不调整为软键盘腾出空间。 相反,窗口的内容会自动平移,以便当前的焦点永远不会被键盘遮挡,用户总是可以看到他们正在键入的内容。 这通常不如resize,因为用户可能需要closures软键盘才能与窗口的遮蔽部分进行交互。

根据你的评论,在你的活动清单中使用以下内容

 <activity android:windowSoftInputMode="adjustResize"> </activity> 

正如医生所说,也要记住正确的价值组合:

该设置必须是下表中列出的值之一,或者是一个“状态…”值加上一个“调整…”值的组合。 在任一组中设置多个值 – 例如多个“状态…”值都有未定义的结果。 各个值由竖线(|)分隔。 例如:

 <activity android:windowSoftInputMode="stateVisible|adjustResize" . . . > 

adjustResize =调整页面内容的大小

adjustPan =移动页面内容,而不调整页面内容的大小

您可以在AndroidManifest.xml中为您当前的活动使用android:windowSoftInputMode="stateAlwaysHidden|adjustResize" ,并在样式或rootLayout中使用android:fitsSystemWindows="true"