当软键盘弹出时,Android全屏调整大小

3

我正在开发一个全屏模式的Android应用程序。当软键盘显示时,我希望屏幕能够自动调整。我使用ScrollView使我的屏幕可以扩展到大于最大高度。您可以查看下面的布局XML:

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:id="@+id/RelativeLayout1"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical"
    tools:context="${packageName}.${activityClass}" >

    <VideoView
        android:id="@+id/taskdetail_bgvideo"
        android:layout_width="wrap_content"
        android:layout_height="match_parent"
        android:layout_alignParentBottom="true"
        android:layout_alignParentLeft="true"
        android:layout_alignParentRight="true"
        android:layout_alignParentTop="true" />

    <ScrollView
        android:id="@+id/taskdetail_scroll"
        android:layout_width="match_parent"
        android:layout_height="wrap_content" >

        <LinearLayout
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:orientation="vertical" >

            <!-- Other Widgets -->

        </LinearLayout>
    </ScrollView>
</RelativeLayout>

背景中的VideoView放置在整体布局中,以创建背景视频。

我尝试了Android如何在软键盘可见时调整全屏模式下的布局中的解决方法,但在我的情况下,它并没有像预期的那样工作。当我选择最底部的TextView时,整个屏幕都被推向顶部,留下一个非常大的黑色区域,介于软键盘和活动屏幕之间。请查看下面的截图(抱歉,声望还很低,无法直接发布图片 :( )

巨型黑洞

所以你有没有可能的想法来解决这种奇怪的行为?此外,我还尝试了将softInputMode设置为ADJUST_RESIZE或ADJUST_PAN,两种设置都会这样做。当我将其设置为ADJUST_NOTHING时,什么也没有调整。

当我不使用上述解决方法时,我无法滚动视图到最底部的小部件,但窗口视图却被平移到了焦点TextView。我相信这实际上是主要的罪魁祸首,但我不知道该如何修复。

提前感谢 :)

4个回答

9
如果您的主题中有属性<item name="windowFullscreen">true</item>,那么android:windowSoftInputMode="adjustResize"无法起作用。

0

尝试更改

<ScrollView
    android:id="@+id/taskdetail_scroll"
    android:layout_width="match_parent"
    android:layout_height="wrap_content" >

<ScrollView
    android:id="@+id/taskdetail_scroll"
    android:layout_width="match_parent"
    android:layout_height="match_parent" >

试试这个.. 把ScrollView作为根元素,听起来像是这样的..<ScrollView> <RelativeLayout> </RelativeLayout></ScrollView> - Igor Morais

-1
尝试在你的AndroidManifest.xml中的<activity tag declaration中添加以下属性。
android:windowSoftInputMode="stateHidden|adjustPan"

不幸的是,它并不像我预期的那样工作。当键盘显示时,我不想滚动屏幕。我希望它可以调整活动屏幕大小以适应软键盘上方的可用区域。但由于活动处于全屏状态,所以adjustResize将无法起作用。 - Gilang

-1

你需要编写

android:windowSoftInputMode="stateHidden|adjustPan"

在你的清单文件中。

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接