您的位置:首页 > 其它

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

2015-03-25 13:26 423 查看
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"


这使得作为重力是底部总是显示底部的布局。
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: