代码之家  ›  专栏  ›  技术社区  ›  Mathias Conradt

当显示软键盘时,Android如何决定是否向上移动布局?

  •  6
  • Mathias Conradt  · 技术社区  · 15 年前

    当显示软键盘时,Android如何决定是否向上移动布局?

    android:windowSoftInputMode="adjustResize|adjustResize|adjustUnspecified" 存在,如这里所述 http://developer.android.com/guide/topics/manifest/activity-element.html#wsoft

    我有两个活动,布局基本相同,但第一个活动是使用 带按钮的滚动视图 . 其余的是相同的,相同的按钮数量,相同的元素高度,等等。

    现在,当我按搜索按钮打开搜索输入栏时,在 我的第一个活动是,整个布局都向上移动。 在第二个活动中,布局没有上移,但软键盘只是显示在它的顶部。 这就是我想要它表现出来的样子。如何使用ListView实现与我的活动相同的效果?

    android:windowSoftInputMode 属性,但即使我这么做了,也没有任何区别;我尝试了所有三个值(adjustPan、adjustResize、adjustUndefined,没有任何区别)。

    这是我的布局:

    (一) http://pastebin.com/5zzVxjbK

    (二) http://pastebin.com/KFtPuHvP

    有趣的是:当我在布局1(左)中设置ListView可见性为视图.不可见,则布局不会上移!

    alt text

    1 回复  |  直到 15 年前
        1
  •  0
  •   Paul Burke    15 年前

    我可以通过相对布局和设置来实现这一点 android:windowSoftInputMode="adjustPan" 是这样的:

    <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
        android:layout_width="fill_parent" android:layout_height="fill_parent" >
    
        <include android:id="@+id/Header" layout="@layout/header"
            android:layout_width="fill_parent" android:layout_height="wrap_content" />
    
        <ListView android:id="@+id/android:list" android:layout_width="fill_parent"
            android:layout_height="wrap_content" android:layout_below="@id/Header"
            android:layout_above="@+id/Footer"  />
    
        <include android:id="@id/Footer" layout="@layout/footer"
            android:layout_width="fill_parent" android:layout_height="wrap_content"
            android:layout_alignParentBottom="true" />
    </RelativeLayout>