Android: windowSoftInputMode =“adjustResize” 对UI没有影响

标签 android android-layout

我知道在这方面关于 SO 也有类似的问题。但我完全无能为力。
我有一个多行编辑文本,它被放置在 LinearLayout 中的几个元素之后。而且在输入文字的时候,是隐藏的。
解决方案是在 list 文件中添加属性 android:windowSoftInputMode="adjustResize"。它没有效果。
进一步搜索SO,我发现我需要在根布局元素中添加一个属性android:fitsSystemWindows="true"。然而,它不起作用。什么问题?

这是 list 文件:

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="com.mytasks">
    <application
        android:allowBackup="true"
        android:icon="@drawable/ic_launcher"
        android:label="@string/app_name"
        android:theme="@style/AppTheme" >
        <activity
            android:name=".MainActivity"
            android:label="@string/app_name" >
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />

                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>
        <activity
            android:name=".TaskDetails"
            android:label="@string/title_activity_task_details"
            android:windowSoftInputMode="adjustResize"
            >
        </activity>
    </application>
</manifest>

Activity 布局 xml 文件:

<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:paddingLeft="@dimen/activity_horizontal_margin"
    android:paddingRight="@dimen/activity_horizontal_margin"
    android:paddingTop="@dimen/activity_vertical_margin"
    android:orientation="vertical"
    android:layout_alignParentBottom="true"
    android:fitsSystemWindows="true"
    android:paddingBottom="@dimen/activity_vertical_margin" tools:context="com.mytasks.TaskDetails">

    <TextView
        android:text="Short description of the task"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:textStyle="bold"
        android:textSize="@dimen/abc_text_size_medium_material"
        android:typeface="sans"
        android:layout_margin="7dp"
     />

    <EditText
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:id="@+id/sd"
        android:hint="e.g. To meet doctor"
        android:layout_margin="7dp"
    />

    <TextView
        android:text="Type"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_margin="7dp"
        android:textStyle="bold"
        android:textSize="@dimen/abc_text_size_medium_material"
        android:typeface="sans"

        />

    <Spinner
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:id="@+id/type"
        android:entries="@array/type"
        android:layout_margin="7dp"
    />

    <TextView
        android:text="Priority"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_margin="7dp"
        android:textStyle="bold"
        android:textSize="@dimen/abc_text_size_medium_material"
        android:typeface="sans"
        />

    <Spinner
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:id="@+id/priority"
        android:entries="@array/priority"
        android:layout_margin="7dp"
    />

    <TextView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="Description"
        android:layout_margin="7dp"
        android:textStyle="bold"
        android:textSize="@dimen/abc_text_size_medium_material"
        android:typeface="sans"
        />

    <ScrollView
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_margin="7dp"
        >

    <EditText
        android:layout_width="match_parent"
        android:layout_height="fill_parent"
        android:singleLine="false"
        android:id="@+id/description"
        android:inputType="textMultiLine"
        android:gravity="top"
        android:lines="4"
        android:maxLines="10"
        android:scrollbars="vertical"
    />
    </ScrollView>

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_margin="7dp"
        >
        <Button
            android:id="@+id/save"
            android:text="Save"
            android:layout_weight="1"
            android:layout_width="0dip"
            android:layout_height="wrap_content" />
        <Button
            android:id="@+id/cancel"
            android:text="Cancel"
            android:layout_weight="1"
            android:layout_width="0dip"
            android:layout_height="wrap_content" />
    </LinearLayout>
</LinearLayout>

截图:

最初:

enter image description here

键盘显示后:

enter image description here

最佳答案

使用 adjustPan 可以平移屏幕。

或者将屏幕的所有字段都放入 ScrollView 中,这样可以减少该区域。

关于Android: windowSoftInputMode =“adjustResize” 对UI没有影响,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29714636/

相关文章:

Android:无论前一个滴答声尚未完成,计时器都会滴答作响吗?

java - Android API 25 之后,SQLite db 文件在设备/模拟器上的位置是什么?

android - 在 Android 中的布局中屏蔽图像

android - 为什么相同的 layout_weight 导致 Android ImageButton 和 Button 的宽度不同?

java - 安装带有 flavor 包的应用程序时出错

android - 将 facebook 的个人资料图片设置为 LinearLayout 背景

android - 从 Activity 访问 Fragment 中的 View 绑定(bind)

android - 使用字符串数组填充 Spinner

android - 百分比框架布局 : You must supply a layout_width attribute

android - 跨方向更改保留 xml fragment