windowSoftInputMode属性介绍及设置adjustResize不起作用的解决方案

android:windowSoftInputMode

activity主窗口与软键盘的交互模式,可以用来避免输入法面板遮挡问题,Android1.5后的一个新特性。

这个属性能影响两件事情:

【一】当有焦点产生时,软键盘是隐藏还是显示

【二】是否减少活动主窗口大小以便腾出空间放软键盘

它的设置必须是下面列表中的一个值,或一个state…”值加一个adjust…”值的组合。在任一组设置多个值——多个state…”values,例如&mdash有未定义的结果。各个值之间用|分开。例如:<activity android:windowSoftInputMode="stateVisible|adjustResize". . . >

在这设置的值("stateUnspecified""adjustUnspecified"以外)将覆盖在主题中设置的值


各值的含义:

【A】stateUnspecified:软键盘的状态并没有指定,系统将选择一个合适的状态或依赖于主题的设置

【B】stateUnchanged:当这个activity出现时,软键盘将一直保持在上一个activity里的状态,无论是隐藏还是显示

【C】stateHidden:用户选择activity时,软键盘总是被隐藏

【D】stateAlwaysHidden:当该Activity主窗口获取焦点时,软键盘也总是被隐藏的

【E】stateVisible:软键盘通常是可见的

【F】stateAlwaysVisible:用户选择activity时,软键盘总是显示的状态

【G】adjustUnspecified:默认设置,通常由系统自行决定是隐藏还是显示

【H】adjustResize:该Activity总是调整屏幕的大小以便留出软键盘的空间

【I】adjustPan:当前窗口的内容将自动移动以便当前焦点从不被键盘覆盖和用户能总是看到输入内容的部分


遇到的问题


我有以下布局

<?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
        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>

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

帮助

解决方法 1:

若要修复我的问题了这里它是。

我通过以下方式修改主要滚动视图的第一个孩子

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

我添加了即

    android:layout_gravity="bottom"

这使得作为重力是底部总是显示底部的布局。

  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 2
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值