Difference between adjustResize and adjustPan in a

2019-01-01 00:33发布

问题:

I tried to write a code which is used to re-size the UI components when soft-keyboard appears. When I use adjustResize, it res-size the UI components and at the same time adjustPan gave me same output. I want to know the difference between them and when to use each component? Which one(adjustPan or adjustResize) is good for resizing UI?

Here is my 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>

and the menifest file:

<?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>

回答1:

From the Android Developer Site link

\"adjustResize\"

The activity\'s main window is always resized to make room for the soft keyboard on screen.

\"adjustPan\"

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.

according to your comment, use following in your activity manifest

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


回答2:

adjustResize = resize the page content

adjustPan = move page content without resizing page content



回答3:

As doc says also keep in mind the correct value combination:

The setting must be one of the values listed in the following table, or a combination of one \"state...\" value plus one \"adjust...\" value. Setting multiple values in either group — multiple \"state...\" values, for example — has undefined results. Individual values are separated by a vertical bar (|). For example:

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


回答4:

You can use android:windowSoftInputMode=\"stateAlwaysHidden|adjustResize\" in AndroidManifest.xml for your current activity, and use android:fitsSystemWindows=\"true\" in styles or rootLayout.