在安卓系统中,将windowSoftInputMode设置为stateHidden|adjustResize无效。

5

我有以下布局

<?xml version="1.0" encoding="utf-8"?>
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_gravity="bottom"
android:background="@drawable/background_grey"
android:fillViewport="true"
android:focusable="true"
android:focusableInTouchMode="true"
android:orientation="vertical" >

<RelativeLayout
    android:layout_width="fill_parent"
    android:layout_height="wrap_content" >

    <RelativeLayout
        android:id="@+id/logo_layout"
        android:layout_width="fill_parent"
        android:layout_height="@dimen/layout_height"
        android:layout_alignParentTop="true"
        android:background="@drawable/logo_container" >

        <!-- some layout components-->
    </RelativeLayout>

    <RelativeLayout
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:layout_below="@+id/logo_layout"
        android:layout_margin="@dimen/default_margin" >

                    <!-- some layout components-->

        <RelativeLayout
            android:id="@+id/activation_code_entry_layout"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_below="@+id/activation_body_second_paragraph"
            android:layout_centerHorizontal="true"
            android:layout_marginTop="20dp"
            android:background="@drawable/enter_passcode_background"
            android:gravity="center_vertical" >

                        <!-- some layout components-->

            <EditText
                android:id="@+id/activationCode"
                style="@style/FormField"
                android:layout_alignParentRight="true"
                android:layout_marginRight="@dimen/side_margin"
                android:hint="@string/activation_enter_code"
                android:inputType="number"
                android:maxLength="10"/>

                        <!-- some layout components-->
        </RelativeLayout>

                    <!-- some layout components-->
    </RelativeLayout>
</RelativeLayout>

</ScrollView>

在应用程序清单文件中,我将Activity设置为

<activity
        android:name=".activities.MyActivity"
        android:enabled="true"
        android:label="@string/app_name"
        android:screenOrientation="portrait"
        android:theme="@android:style/Theme.NoTitleBar"
        android:windowSoftInputMode="stateHidden|adjustResize" >
    </activity>

但当软键盘出现时,视图不会向上滚动。

这是我找到的唯一可行的解决方案: https://dev59.com/fGoy5IYBdhLWcg3wq_3O#30019136 - Analizer
2个回答

5

2
我成功解决了我的问题。这是解决方法:
我修改了主滚动视图的第一个子视图,具体如下:
<RelativeLayout
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:layout_gravity="bottom" >

即我添加了
    android:layout_gravity="bottom"

这会使得布局总是以底部为重心而显示底部。

希望这能帮助其他人。

祝好!


基本上就是我需要的。不过我把我的设置为“填充”。 - Vas

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接