首页
学习
活动
专区
工具
TVP
发布
社区首页 >问答首页 >ImageView周围不需要的填充

ImageView周围不需要的填充
EN

Stack Overflow用户
提问于 2011-04-29 17:45:34
回答 5查看 77.5K关注 0票数 150

我需要在我的所有活动/视图中包含一个标题图形。带有标题的文件名为header.xml:

代码语言:javascript
复制
<?xml version="1.0" encoding="utf-8"?>
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
  android:layout_width="fill_parent" 
  android:layout_height="wrap_content"
  android:background="#0000FF" 
  android:padding="0dip">

  <ImageView xmlns:android="http://schemas.android.com/apk/res/android"
    android:src="@drawable/header"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:layout_margin="0dip"
    android:layout_marginTop="0dip"
    android:layout_marginBottom="0dip"
    android:padding="0dip"
    android:paddingTop="0dip"
    android:paddingBottom="0dip"
    android:layout_gravity="fill"
    android:background="#00FF00"
    />
</FrameLayout>

注意android:background="#00FF00" (绿色),它只是可视化的目的。

我将它们包含在我的视图中,如下所示:

代码语言:javascript
复制
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
  xmlns:android="http://schemas.android.com/apk/res/android"
  android:layout_width="fill_parent"
  android:layout_height="fill_parent"
  android:orientation="vertical"
  style="@style/white_background">

  <include layout="@layout/header" />
  (...)

因此,当我实际尝试它时,结果看起来像左边的图像,而不是它应该看起来的样子(右):

(1)这个-橙色部分-是有问题的image/ImageView

(2)不受欢迎的绿色边框。注意:通常情况下,绿色区域是透明的-因为我设置了background,所以它才是绿色的。

请注意顶部图像周围的绿色边框;它是ImageView的一部分,我只是弄不明白它为什么会在那里,也不知道如何才能摆脱它。它将所有的填充和边距设置为0(但当我省略它们时,结果是相同的)。图像是480x64pxjpeg*,我把它放在res/drawable中(虽然不是在drawable-Xdpi中)。

(* jpeg,因为我似乎偶然发现了旧的png gamma问题-一开始我解决了这个问题,将绿色边框设置为与图片相同的橙色,颜色不匹配。)

我在我的htc desire/2.2/Build 2.33.163.1和模拟器上尝试了它。此外,我在#android-dev中向某人描述了这个问题;她可以重现这个问题,但也没有任何解释。构建目标是1.6。

update @tehgoose:此代码产生完全相同的top+bottom填充结果。

代码语言:javascript
复制
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
  xmlns:android="http://schemas.android.com/apk/res/android"
  android:layout_width="fill_parent"
  android:layout_height="fill_parent"
  android:orientation="vertical"
  style="@style/white_background">

  <!-- <include layout="@layout/header" />  -->

  <ImageView
    android:src="@drawable/header"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:background="#00FF00"
    android:layout_weight="0"
    />

  <LinearLayout
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:orientation="vertical"
    android:padding="8dip"
    android:layout_weight="1">

    (... rest of the elements)

  </LinearLayout>
</LinearLayout>
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/5830503

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档