【问题标题】:ScrollView does not respond to keyboardScrollView 不响应键盘
【发布时间】:2012-10-09 11:29:04
【问题描述】:

我对 ScrollViews 中的 EditText 滚动行为有问题,通常如果键盘在其上打开,它会向上滚动滚动内的内容。但是如果你动态填充滚动视图内的布局,键盘向上推整个屏幕,其他人之前都遇到过这个问题。 提前致谢。

<ScrollView
    android:id="@+id/scroll_view"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:layout_below="@+id/header_area" >

        <LinearLayout
            android:id="@+id/contentHolder"
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:orientation="vertical" >
        </LinearLayout>
</ScrollView>

此示例在滚动视图中正常工作,线性布局滚动,但即使键盘关闭也显示滚动。我不能使用固定高度。

 <ScrollView
        android:id="@+id/scroll_view"
        android:layout_width="fill_parent"
        android:layout_height="100dip"
        android:layout_below="@+id/header_area" >

            <LinearLayout
                android:id="@+id/contentHolder"
                android:layout_width="fill_parent"
                android:layout_height="wrap_content"
                android:orientation="vertical" >
            </LinearLayout>
    </ScrollView>

我在下面尝试了 xml,它在新项目中按预期工作,但在我的项目中推高了窗口。我发现其他一些人遇到了这个问题,我会尽快分享解决方案。

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


    <RelativeLayout
        android:id="@+id/header_area"
        android:layout_width="match_parent"
        android:layout_height="50dip" >
    </RelativeLayout>

    <ScrollView
        android:id="@+id/scroll_view"
        android:layout_width="fill_parent"
        android:layout_height="fill_parent">

        <LinearLayout
            android:id="@+id/contentHolder"
            android:layout_width="fill_parent"
            android:layout_height="fill_parent"
            android:orientation="vertical" >

            <EditText 
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"/>
            <EditText 
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"/>
            <EditText 
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"/>
            <EditText 
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"/>
            <EditText 
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"/>
            <EditText 
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"/>
        </LinearLayout>
    </ScrollView>

</LinearLayout>

【问题讨论】:

  • 您是否在 LinearLayout 中添加新视图,父视图是 ScrollView?
  • 是的,在scrollView中使用linearLayout。将视图推送到 @+id/contentHolder
  • 您在 LinearLayout 右侧有多个 EditText。能否请您显示问题的屏幕截图。
  • 无法分享屏幕截图,但添加了新布局。顺便说一句,找到了问题,这一切都与全屏主题有关。感谢您的回复。
  • 是的,Android 现在仍然支持 Activity 全屏时软键盘调整大小。

标签: android android-edittext android-scrollview


【解决方案1】:
<application
    android:icon="@drawable/is_logo_iphone"
    android:label="@string/app_name"
    android:theme="@android:style/Theme.Black.NoTitleBar.Fullscreen" >

问题是“全屏”主题不支持调整大小。使用

    android:theme="@android:style/Theme.Black.NoTitleBar"

解决问题。
感谢您的回答。

【讨论】:

    【解决方案2】:

    那是因为您的滚动视图是可调整大小的。尝试将滚动视图的高度设置为 match_parent。

    尝试在滚动视图中设置 android:fillViewport="true"。

    此外,您不会碰巧在清单的活动标签中添加以下内容:android:windowSoftInputMode="adjustResize" 这几乎会毁掉我们所有的努力。如果清单中有以下内容,请将其删除。

    您可能必须配置清单。 Here is a list 软键盘的可能配置。你想使用的可能是android:windowSoftInputMode="adjustPan"

    【讨论】:

    • 我已经尝试过每种组合,但这也不起作用。谢谢。
    • @ymutlu 添加了另一个可能的解决方案
    • 谢谢,试过了,但没有反应。我可能做错了什么。尝试了一个运行良好的空项目。
    • 嗯,我添加了另一个可能的罪魁祸首:)
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2013-10-28
    • 1970-01-01
    • 2015-02-02
    • 1970-01-01
    • 2021-05-31
    • 1970-01-01
    • 2014-07-11
    相关资源
    最近更新 更多