【问题标题】:Massive unwanted whitespace with LinearLayout in ScrollViewScrollView 中带有 LinearLayout 的大量不需要的空白
【发布时间】:2013-02-16 22:43:00
【问题描述】:

我有一个带有自定义 ImageView 和两个 TextEdits 的布局;一上一下。为了使它适合多个屏幕,我用 ScrollView 包围了整个东西。

但是,当添加 ScrollView 时,顶部 TextEdit 和 ImageView 以及 ImageView 和底部 TextEdit 之间会出现巨大的间隙(大约屏幕高度)。

我只是覆盖了 ImageView 中的 onDraw() 方法(并且仍在从那里调用 super.onDraw()

这是我的布局:

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:orientation="vertical" >

    <EditText
        android:id="@+id/top_text"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:ems="10"
        android:hint="@string/top_hint" >

        <requestFocus />
    </EditText>

    <com.javanut13.gememerator.MImageView
        android:id="@+id/image_viewer"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:padding="0dp"
        android:src="@drawable/ic_action_search" />

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

        <EditText
            android:id="@+id/bottom_text"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:ems="10"
            android:layout_weight="3"
            android:hint="@string/bottom_hint" />

        <Button
            android:id="@+id/button1"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_weight="1"
            android:text="@string/button_text" />
    </LinearLayout>
</LinearLayout>

【问题讨论】:

  • 能发个截图吗?我建议启动hierarchyViewer,这可能会提示您哪个视图占用了这么大的空间。

标签: android android-layout scrollview


【解决方案1】:

好的,事实证明我的 ImageView 在缩放图像时没有调整其高度,因此它会保持原始图像的高度(来自我的相机;大约 2000 像素高),因此有一个其上方和下方的巨大空间。

我遇到了这个问题:(Image do not resize with ImageView),它说将android:adjustViewBounds="true" 添加到 ImageView,从而解决了问题。

【讨论】:

    猜你喜欢
    • 2023-04-07
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多