我试图编写一段代码,用于在出现软键盘时重新调整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>
和menifest文件:
<?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>
当我还是一个初学者时,我也有点混淆了adjustResize和adjustPan。上面给出的定义是正确的。br>AdjustResize:主活动的内容被调整大小,以便为软输入(即键盘)腾出空间br>AdjustPan:它不是调整窗口的全部内容,而是只平移内容,以便用户始终可以看到他键入的内容br>AdjustNothing:顾名思义,没有任何内容被调整或平移。无论键盘是否隐藏内容,它都将被打开。brbr>我创建了一个示例以便更好地理解br>下面是我的xml文件:br>
<?xml version="1.0" encoding="utf-8"?>
<android.support.constraint.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".MainActivity">
<EditText
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center"
android:hint="Type Here"
app:layout_constraintTop_toBottomOf="@id/button1"/>
<Button
android:id="@+id/button1"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:text="Button1"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toStartOf="@id/button2"
app:layout_constraintStart_toStartOf="parent"
android:layout_marginBottom="@dimen/margin70dp"/>
<Button
android:id="@+id/button2"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:text="Button2"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintStart_toEndOf="@id/button1"
app:layout_constraintEnd_toStartOf="@id/button3"
android:layout_marginBottom="@dimen/margin70dp"/>
<Button
android:id="@+id/button3"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:text="Button3"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toEndOf="@id/button2"
android:layout_marginBottom="@dimen/margin70dp"/>
</android.support.constraint.ConstraintLayout>
调整页面内容的大小
adjustPan=在不调整页面内容大小的情况下移动页面内容
从Android开发者站点链接
“AdjustreSize”
活动的主窗口总是调整大小,以便为屏幕上的软键盘腾出空间。
“调整”
活动的主窗口没有调整大小来为软键盘腾出空间。相反,窗口的内容是自动平移的,因此当前焦点永远不会被键盘遮挡,用户总是可以看到他们正在键入的内容。这通常不如调整大小,因为用户可能需要关闭软键盘才能进入窗口的模糊部分并与之交互。
根据您的意见,请在您的activity舱单中使用以下内容
<activity android:windowSoftInputMode="adjustResize"> </activity>
我正在开发一个聊天应用,它有背景聊天图像和默认键盘,当我必须使用背景图像时它会缩小,但当我使用android:windowsoftinputmode=“adjustresize”时它工作很好,但键盘隐藏edittext,如果我使用android:windowsoftinputmode=“adjustpan”键盘显示很好,但图像缩小,我如何在单个活动上使用这两个选项 如果在清单中同时使用editte
当用户单击LoginFragment上的一个按钮时,我将打开另一个名为forgetpassword的片段。这是一个webview,url正在从远程服务器加载。而html中的文本字段是通过软键盘隐藏的。所以我尝试使用adjustResize,它工作得很好。但是loginfragment中的editText小部件被键盘隐藏了。 如何在我的活动中实现两个标志。请帮帮我。
我有一个列表视图,每行都有EditText。我的问题是,当我单击EditText时,adjustPan正在工作(我的意思是EditText位于软键盘上方),但当我开始输入字母时,EditText会隐藏在键盘上。 请帮帮我...多谢
我正在使用此库:https://github.com/yshrsmz/KeyboardVisibilityEvent检测键盘何时打开或关闭,这取决于android清单的输入。 此库可以完美地检测软键盘的打开和关闭事件,但由于adjustResize参数,我的内容被推到了视图之外。 > Java: XML: 因此,通过调整第二个编辑文本的行,这非常有效,因此我在键盘上方键入,但当我关闭键盘时,滚动到
我正在开发一个类似社交媒体的应用程序,人们可以在那里分享照片和视频,比如Instagram。这就是为什么相机对我的应用程序非常重要。现在相机2应用程序接口让我困惑。我想在应用程序接口11级运行我的应用程序。我知道相机2只在应用程序接口21级可用。所以,我需要设计两个应用程序接口一个(相机)用于旧版本,第二个(相机2)用于更高版本。问题是我刚开始学习Android,我不知道这两个应用程序接口之间的主
这两者有什么不同? 我用哪一个更好?
本文向大家介绍Android中asset和raw的区别详解,包括了Android中asset和raw的区别详解的使用技巧和注意事项,需要的朋友参考一下 *res/raw和assets的相同点: 1.两者目录下的文件在打包后会原封不动的保存在apk包中,不会被编译成二进制。 *res/raw和assets的不同点: 1.res/raw中的文件会被映射到R.java文件中,访问的时候直接使用资源ID即
问题内容: @id/和之间的区别是什么@+id/? 在@+id/加号中+指示创建一个新的资源名称并将其添加到R.java文件中,但是那又如何@id/呢?从:的文档中,ID当引用Android资源时ID,不需要加号,但必须添加android包名称空间,如下所示: 但是在下面的图像中,Eclipse并未提出任何建议@android:id/。 该图显示了对@ / id和@ + / id的建议 是和一样吗