android中adjustResize和adjustPan的区别? [英] Difference between adjustResize and adjustPan in android?

查看:42
本文介绍了android中adjustResize和adjustPan的区别?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

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?

这是我的 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>

和menifest文件:

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>

推荐答案

来自 Android 开发者网站链接

调整调整大小"

活动的主窗口总是调整大小,以便为软屏幕上的键盘.

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>

这篇关于android中adjustResize和adjustPan的区别?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆