我需要在我的所有活动/视图中包含标题图形.带有头的文件称为头文件.xml:
<?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"
(绿色),这只是可视化的目的.
我把它们包含在我的观点中,如下所示:
<?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" />
(...)
所以,当我实际try 时,结果看起来像左边的图像,而不是它应该是什么样子(右):
(1)这-橙色部分是有问题的image/ImageView
(2)不受欢迎的绿色边框.注意:通常情况下,绿色区域是透明的-因为我设置了background
,所以它才是绿色的.
请注意顶部图像周围的绿色边框;它是ImageView的一部分,我只是想不明白它为什么会在那里,或者我如何才能go 掉它.它将所有填充和边距设置为0(但是当我省略它们时,结果是相同的).图像是480x64px的jpeg*,我把它放在res/Drawable中(虽然不是drawable-Xdpi
个中的一个).
(*jpeg,因为我似乎偶然发现了旧的PNG Gamma问题-一开始我解决了这个问题,将绿色边框设置为与图片相同的橙色, colored颜色 不匹配.)
我在我的htc desire/2.2/Build 2.33.163.1和模拟器上试用了它.我还向#android dev;她可以重现这个问题,但也没有解释.构建目标是1.6.
update@tehgoose:这段代码产生完全相同的顶部+底部填充结果.
<?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>