Android adjustResize布局使用软键盘调整大小

时间:2011-09-07 11:21:35

标签: android layout android-softkeyboard

我很难获得一个小的EditText以及两个按钮对齐到屏幕底部软件键盘的底部。基本上我的问题是,每次我打开我的活动(标记为 adjustResize | stateAlwaysVisible )和布局:

<LinearLayout 
xmlns:android="http://schemas.android.com/apk/res/android"
android:gravity="bottom" 
android:layout_height="match_parent" 
android:orientation="vertical" 
android:layout_width="match_parent" 
android:layout_alignParentBottom="true">

    <LinearLayout android:orientation="vertical" android:layout_height="wrap_content" android:layout_width="match_parent" android:id="@+id/soft_input_edit_placeholder">
        <EditText android:layout_width="match_parent" android:layout_height="wrap_content" android:id="@+id/editText1">
            <requestFocus></requestFocus>
        </EditText>
    </LinearLayout>
    <LinearLayout android:layout_height="wrap_content" android:layout_width="match_parent" android:weightSum="2" android:id="@+id/soft_input_layout_buttons">
        <Button android:layout_width="0dp" android:text="xxx Submit xxx" android:layout_height="wrap_content" android:id="@+id/soft_input_button_submit" android:layout_weight="1"></Button>
        <Button android:layout_width="0dp" android:text="xxx Cancel xxx" android:layout_height="wrap_content" android:id="@+id/soft_input_button_cancel" android:layout_weight="1"></Button>
    </LinearLayout>
</LinearLayout>

键盘向上滑动,它会调整活动的大小,以便仅显示编辑文本,当我隐藏它时(至少键盘上有一个允许我隐藏它的按钮),布局保持原位,也就是说,它永远不会向下滑动,留下一半的屏幕。

我读到在大多数情况下,通过向布局引入一些可伸缩控件来实现对齐,但我真的不希望在那里有任何形式的ListView;我尝试过使用RelativeLayout,仍然没有去。将一个嵌入另一个 - 仍然没有运气。我非常感谢你提出的任何建议,我的想法已经不多了......

谢谢!

1 个答案:

答案 0 :(得分:2)

问题出现在选定的主题中。我的活动在清单中应用了全屏主题(我不知道它可能以这种方式影响视图);将其更改为非全屏已解决了我的问题(虽然它不能只是任何其他主题)

我通过将活动主题设置为 Theme.Translucent 并将布局主题设置为主题(完全没有主题)来实现我的目标;将 @android:drawable / bottom_bar 应用到主LinearLayout,最后将主布局的重力设置为 bottom ,这样就得到了我想要的结果。

相关问题