Android:ScrollView不会滚动键盘输出

时间:2013-03-11 16:12:44

标签: java android android-layout android-softkeyboard android-scrollview

我有一些包含一些视图的布局,其中一个是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"

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

提前致谢!

11 个答案:

答案 0 :(得分:45)

我遇到了同样的问题,我在清单中检查了我的活动,之所以没有用,是因为我没有使用这个属性:

android:windowSoftInputMode="adjustResize"

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

答案 1 :(得分:34)

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

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

答案 2 :(得分:14)

就我而言,上述情况都没有奏效。

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

答案 3 :(得分:11)

android:windowSoftInputMode="stateHidden|adjustResize"添加到AndroidManifest.xml文件中的代码中。这将导致在显示软键盘后屏幕调整到左侧空间。所以,你可以轻松滚动。

答案 4 :(得分:2)

就我而言,直到我删除

,以上任何解决方案都无法使用

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

在我的活动中,我使用该代码获得全屏显示。也许在某些情况下,请尝试删除任何全屏设置以使上述任何解决方案都起作用。

答案 5 :(得分:2)

就我而言,我必须从样式中删除以下属性以使其起作用。

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

答案 6 :(得分:0)

我的问题是使用Horizo​​ntalScrollView。在我的情况下,我必须将Horizo​​ntalScrollView设置为:

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

并删除:

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

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

android:windowSoftInputMode=""

我希望这可以帮助任何人来解决这个奇怪的错误。

答案 7 :(得分:0)

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

答案 8 :(得分:0)

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

1。在ScrollView中添加

ERROR in ./node_modules/css-loader/dist/cjs.js!./node_modules/sass-loader/dist/cjs.js!./src/styles/styles.scss
Module build failed:
@import './base/base';
^
      Media query expression must begin with '('
      in C:\React\indecision-app\src\styles\styles.scss (line 2, column 1)
 @ ./src/styles/styles.scss 4:14-125
 @ ./src/app.js
 @ multi (webpack)-dev-server/client?http://localhost:8080 ./src/app.js
webpack: Failed to compile.

2。添加清单

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

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

答案 9 :(得分:0)

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

答案 10 :(得分:-3)

<LinearLayout
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:orientation="horizontal"
    android:id="@+id/llayout"
    android:visibility="visible">

    <EditText
        android:id="@+id/edittexte"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_weight="1"
        android:ems="10"
        android:inputType="textPersonName"
        android:text="Name" />

    <Button
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_weight="1"
        android:text="SAVE"
        android:id="@+id/buttone"/>

</LinearLayout>

在Android清单中试试 ..