Android:ScrollView 无法在键盘退出时滚动

问题描述 投票:0回答:12

我有一个带有一些视图的布局,其中一个是 EditText。布局很容易适合一页,但是,当软键盘退出时,布局不会滚动。 这是我的布局的回顾:

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:background="@drawable/background" >

    <ScrollView
        android:id="@+id/ScrollView1"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:layout_alignParentTop="true" >

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

            <CheckBox/>

            <TextView/>

            <LinearLayout>
                <EditText>
                    <requestFocus />
                </EditText>
            </LinearLayout>

            <TextView/>

            <LinearLayout>
                <Spinner/>
            </LinearLayout>

        </LinearLayout>

    </ScrollView>

    <Button
        android:layout_alignParentBottom="true" />

</RelativeLayout>

在我的清单中我已经声明了该属性:

android:windowSoftInputMode="adjustResize|stateHidden"

有谁知道为什么它不起作用以及如何确保它起作用?

java android android-layout android-softkeyboard android-scrollview
12个回答
67
投票

我遇到了同样的问题,我检查了清单中的活动,它不起作用的原因是因为我没有使用此属性:

android:windowSoftInputMode="adjustResize"

现在效果很好,不需要做额外的锚点。


38
投票

好吧,显然 ScrollView 的

android:layout_height
不能设置为
wrap_content
。我将其设置为
match_parent
并将
android:layout_above
设置为页面底部的按钮。

不要问我为什么,但这解决了问题。


27
投票

就我而言,以上方法都不起作用。

我的主题中有

item name="android:windowTranslucentStatus">true</item>
。通过在我的滚动视图所在的父布局中设置
android:fitsSystemWindows="true"
来修复它。


13
投票

android:windowSoftInputMode="stateHidden|adjustResize"
添加到 AndroidManifest.xml 文件中的标记中。这将导致在显示软键盘后将屏幕大小调整到左侧空间。因此,您将能够轻松滚动。


6
投票

如果您的第一个片段完美滚动,而第二个片段没有滚动,那么您应该使用第二个片段替换并执行以下操作

1.在ScrollView中添加

android:fillViewport="true"
android:fitsSystemWindows="true"

2.添加Manifest

android:windowSoftInputMode="adjustResize|stateVisible"

如果您添加片段,那么我的建议是您需要替换片段


5
投票

就我而言,上述任何解决方案都不起作用,直到我REMOVE

getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN);

在我的活动中,我使用该代码来获得全屏显示。也许在某些情况下,尝试删除所有全屏设置以使上述解决方案有效。


3
投票

就我而言,我必须从我的样式中删除以下属性才能使其正常工作。

<item name="android:windowFullscreen">true</item>

1
投票

我的问题是 HorizontalScrollView。就我而言,我必须将 HorizontalScrollView 设置为:

android:layout_width="match_parent"
android:layout_height="match_parent"

并删除:

 android:layout_above="@+id/closeButton"
 android:layout_below="@+id/logo"

在 AndroidManifest.xml 中,活动设置为:

android:windowSoftInputMode=""

我希望这可以帮助任何遇到这个奇怪错误的人。


0
投票

就我而言,解决这个问题的方法是在底部设置一个缺失的约束。我的 ScrollView 有顶部、右侧和左侧约束,但没有底部约束。从各个方面限制之后,它开始与上面的textview重叠,这促使我尝试将高度设置为0dp,这似乎解决了问题。


0
投票

我也面临着同样的问题。

变更前

android:windowSoftInputMode="adjustResize|adjustPan"

改变后

android:windowSoftInputMode="adjustResize"

现在工作正常,不需要做额外的锚点。


-2
投票

尝试将 ScrollView 设置为父布局。它对我来说就像魅力一样!


-6
投票
<activity 
    android:windowSoftInputMode="adjustResize"
>

在android清单中尝试这个..

© www.soinside.com 2019 - 2024. All rights reserved.