【问题标题】:Android ScrollView doesn't scroll when the keyboard is up键盘启动时Android ScrollView不滚动
【发布时间】:2013-07-09 19:13:36
【问题描述】:

我有一个没有填满屏幕的视图,但是当键盘出现时,您不能向下滚动到现在覆盖的几个字段。我尝试在清单和类中添加adjustSize、adjustPan。 xml 类似于以下条目:

<?xml version="1.0" encoding="utf-8"?>
<ScrollView
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/s"
    android:layout_height="fill_parent"
    android:layout_width="fill_parent"
    >

<TableLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:id="@+id/TableLayout1"
    android:layout_width="match_parent"
    android:layout_height="wrap_content" >

    <TableRow
        android:id="@+id/tableRow1"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content" >

        <!-- TextViews & EditTexts are here -->
    </TableRow>
        <TableRow
        android:id="@+id/tableRow2"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content" >

        <!-- TextViews & EditTexts are here -->
    </TableRow>
        <TableRow
        android:id="@+id/tableRow3"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content" >

        <!-- TextViews & EditTexts are here -->
    </TableRow>
        <TableRow
        android:id="@+id/tableRow4"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content" >

        <!-- TextViews & EditTexts are here -->
    </TableRow>
        <TableRow
        android:id="@+id/tableRow5"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content" >

        <!-- TextViews & EditTexts are here -->
    </TableRow>



</TableLayout>
</ScrollView>

当键盘出现时,我需要能够滚动浏览editTexts和TextViews

【问题讨论】:

    标签: android keyboard scrollview


    【解决方案1】:

    Flipbed 提供的链接是您解决方案的答案。如果您只是将“adjustResize”添加到清单中的活动,则无需实施解决方法。您之前遇到的问题是您使用的是adjustPan。在 adjustPan 不调整窗口大小的地方,它平移视图,以便任何有焦点的东西都不会被软键盘遮挡。如果您查看 Google 的文档(请参阅下面的链接),这将是有意义的。

    例子:

    <activity android:name="YourActivity" 
              android:windowSoftInputMode="adjustResize" />
    

    http://developer.android.com/guide/topics/manifest/activity-element.html#wsoft

    【讨论】:

    • 抱歉延迟回复。不过,这确实奏效了。非常感谢。
    • 不,没用。添加它会自动将底部按钮向上移动....我不想要这个。我只想让它在滚动时可见。键盘一打开就不行。
    • @AllTimeKing-Narendra 阅读了 adjustResize 和 adjustPan 之间的区别。如果由于某种原因您确实希望在键盘启动时按钮被键盘遮挡,那么不要做这些事情中的任何一个。对我来说,这听起来像是糟糕的用户体验,但如果这是你需要的,你需要确保你的视图显然是可滚动的。尝试 android:windowSoftInputMode="adjustNothing" 或在 java 代码中执行。但是,这应该是一个新问题,因为这是一个不同的问题。
    • 如果您的活动使用 FULL_SCREEN 样式,则它不起作用。或者您必须在您的代码中REMOVEgetWindow() .getDecorView() .setSystemUiVisibility(View.SYSTEM_UI_FLAG_LAYOUT_STABLE | View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN);
    • 我在我的 ScrollView 而不是 Activity 中应用了这个属性,它工作得很好。谢谢!
    【解决方案2】:

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

    【讨论】:

      【解决方案3】:

      与 NestedScrollView 有类似的问题。更改为 ScrollView 有所帮助。

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2015-02-02
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多