【问题标题】:Empty space above ImageViewImageView 上方的空白区域
【发布时间】:2012-03-14 12:08:54
【问题描述】:

我在 listView 上方有一个静态 ImageView。 但是 imageView 上面显示了一些空白区域。

我怎样才能删除这个空白空间?

-当我使用图像作为 TextView 的背景时,它在父顶部完美对齐

这是我的 ImageView xml:

    <?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent" 
android:layout_height="fill_parent"
android:background="@android:color/background_light"
>

 <ImageView
        android:id="@+id/titlebartear"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:layout_alignParentTop="true"
        android:layout_marginTop="-5dip"
        android:src="@drawable/titlebartear"
        />

 <ListView android:id="@android:id/list" 
    android:paddingTop="0px" 
    android:tag="fileslist"
    android:fastScrollEnabled="true"
    android:smoothScrollbar="true"
    android:layout_width="fill_parent" 
    android:layout_height="fill_parent" 
    android:divider="@color/pijndagboek_light_blue"
    android:dividerHeight="2px"
    android:cacheColorHint="#00000000"
    android:layout_below="@id/titlebartear"
    />

</RelativeLayout>

【问题讨论】:

  • 你能发布你所有的 .xml 文件吗? (通常是它的 main.xml,但您可能已经更改了它。)问题可能出在文件的其他地方。
  • 这是所有布局@JamesWright
  • 谢谢。我不在 ym 笔记本电脑 atm 上,而是在学校电脑上,所以我不能将它复制到 eclipse 中并弄乱它来修复它。我想你在 laout_marginTop 属性中添加了尝试修复它?
  • 谢谢!没有 marginTop 它向我展示了空白空间.. @JamesWright

标签: android xml user-interface listview imageview


【解决方案1】:

有点晚了,但可能会帮助其他遇到此问题的人:

“调整 ViewBounds” 对我有用,当可绘制对象自动缩放其设置的视图的高度时。 (导致图像本身上方和下方出现空白)

【讨论】:

    【解决方案2】:

    将图像设置为 Imageview 的背景。

     <ImageView
            android:id="@+id/titlebartear"
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:layout_alignParentTop="true"
            android:background="@drawable/titlebartear"
            />
    

    【讨论】:

    • 不过,这种方式违背了使用 ImageView 的目的。
    • 空间即将到来,因为您的原始图像可能有该空间
    • 是的,当我将其用作背景时,我的图像可以正确显示。但是我已经通过将 marginTop 设置为 -5dip 找到了解决方案(仍然很奇怪)
    • 不,原始图像没有那个空白空间(@VenkataKrishna)
    【解决方案3】:

    android:layout_marginTop="-5dip"

    工作过:S

    【讨论】: