侧边栏壁纸
博主头像
落叶人生博主等级

走进秋风,寻找秋天的落叶

  • 累计撰写 130562 篇文章
  • 累计创建 28 个标签
  • 累计收到 9 条评论
标签搜索

目 录CONTENT

文章目录

windowSoftInputMode 的属性

2024-05-06 星期一 / 0 评论 / 0 点赞 / 54 阅读 / 5847 字

"adjustResize"The activity's main window is always resized to make room for the soft keyboard on scr

"adjustResize"

The activity's main window is always resized to make room for the soft keyboard on screen.Activity主窗口会缩小自己的显示空间,腾出键盘的位置。

"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.Activity主窗口不会缩小自己的显示空间,而是会移动内部布局(部分布局被移出界面),使当前焦点不被键盘遮挡,用户可以看到输入内容。通常都用adjustResize,少用adjustPan,因为用户需要关闭键盘,才能再和被移除的布局进行交互。

没有滚动控件的布局默认属性为adjustPan有滚动控件的布局默认属性为adjustResize

布局文件

<?xml version="1.0" encoding="utf-8"?><LinearLayout	xmlns:android="http://schemas.android.com/apk/res/android"	xmlns:tools="http://schemas.android.com/tools"	android:layout_width="match_parent"	android:layout_height="match_parent"	android:orientation="vertical"	tools:context="com.df.softinputdemo.MainActivity">	<TextView		android:layout_width="match_parent"		android:layout_height="wrap_content"		android:gravity="center"		android:text="Hello World!"/>	<Button		android:layout_width="match_parent"		android:layout_height="wrap_content"		android:text="Button"		/>	<ScrollView		android:layout_width="match_parent"		android:layout_height="match_parent">		<LinearLayout			android:layout_width="match_parent"			android:layout_height="match_parent"			android:orientation="vertical"			>			<EditText				android:layout_width="match_parent"				android:layout_height="wrap_content"				android:text="1"				/>			<EditText				android:layout_width="match_parent"				android:layout_height="wrap_content"				android:text="2"				/>			<EditText				android:layout_width="match_parent"				android:layout_height="wrap_content"				android:text="3"				/>			<EditText				android:layout_width="match_parent"				android:layout_height="wrap_content"				android:text="4"				/>			<EditText				android:layout_width="match_parent"				android:layout_height="wrap_content"				android:text="5"				/>			<EditText				android:layout_width="match_parent"				android:layout_height="wrap_content"				android:text="6"				/>			<EditText				android:layout_width="match_parent"				android:layout_height="wrap_content"				android:text="7"				/>			<EditText				android:layout_width="match_parent"				android:layout_height="wrap_content"				android:text="8"				/>			<EditText				android:layout_width="match_parent"				android:layout_height="wrap_content"				android:text="9"				/>			<EditText				android:layout_width="match_parent"				android:layout_height="wrap_content"				android:text="10"				/>			<EditText				android:layout_width="match_parent"				android:layout_height="wrap_content"				android:text="11"				/>			<EditText				android:layout_width="match_parent"				android:layout_height="wrap_content"				android:text="12"				/>			<EditText				android:layout_width="match_parent"				android:layout_height="wrap_content"				android:text="13"				/>			<EditText				android:layout_width="match_parent"				android:layout_height="wrap_content"				android:text="14"				/>			<EditText				android:layout_width="match_parent"				android:layout_height="wrap_content"				android:text="15"				/>		</LinearLayout>	</ScrollView></LinearLayout>

截图:第一张为打开界面截图,第二张为点击第10个EditText截图

1、没有滚动控件(ScrollView)的布局

1)设置为adjustPan

2)设置为adjustResize

2、有滚动控件(ScrollView)的布局

1)设置为adjustPan

2)设置为adjustResize

广告 广告

评论区