gpt4 book ai didi

android - android中adjustResize和adjustPan的区别?

转载 作者:IT老高 更新时间:2023-10-28 13:01:52 47 4
gpt4 key购买 nike

我尝试编写一个代码,用于在 软键盘 出现时重新调整 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>

和 list 文件:

<?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 Developer Site link

"adjustResize"

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

"adjustPan"

The activity's main window is not resized to make room for the softkeyboard. Rather, the contents of the window are automatically pannedso that the current focus is never obscured by the keyboard and userscan always see what they are typing. This is generally less desirablethan resizing, because the user may need to close the soft keyboard toget at and interact with obscured parts of the window.

根据您的评论,在您的 Activity list 中使用以下内容

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

关于android - android中adjustResize和adjustPan的区别?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17410499/

47 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com