gpt4 book ai didi

android - Android在显示软键盘时如何判断是否将布局上移?

转载 作者:塔克拉玛干 更新时间:2023-11-02 21:46:09 24 4
gpt4 key购买 nike

Android如何判断显示软键盘时是否上移布局?

注意:我知道 Activity 属性 android:windowSoftInputMode="adjustResize|adjustResize|adjustUnspecified"存在,如此处所述http://developer.android.com/guide/topics/manifest/activity-element.html#wsoft,但就我而言,它似乎没有任何效果。这是我的问题:

我有两个 Activity ,布局几乎相同,但第一个 Activity 使用的是包含按钮列表的ListView。第二个 Activity 包含一个带有按钮的 ScrollView 。其余相同,按钮数量相同,元素高度相同等。

现在,当我按下搜索按钮打开搜索输入栏时,在我的第一个 Activity 中,整个布局都向上移动了。 在第二个 Activity 中,布局没有向上移动,但软键盘只是显示在它上面。这实际上是我希望它的行为方式。我如何才能通过使用 ListView 的 Activity 实现同样的效果?

在我的 list 中,最初我没有指定任何 android:windowSoftInputMode 属性,但即使我指定了,也没有任何区别;我尝试了所有三个值(adjustPan、adjustResize、adjustUndefined,没有任何区别)。

这是我的布局:

1) http://pastebin.com/5zzVxjbK

2) http://pastebin.com/KFtPuHvP

有趣的是:当我将布局 1(左)中的 ListView 可见性设置为 View.INVISIBLE 时,布局不会向上移动!

alt text

最佳答案

我可以通过 RelativeLayout 和设置 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>

如果您想保留 LinearLayout,您可以通过将页脚引力(或 layout_gravity)设置为“底部”来实现此目的,但我不确定。

关于android - Android在显示软键盘时如何判断是否将布局上移?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3651497/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com