2011-05-13 110 views
1

人。我在Activity中使用了RelativeLayout作为头部,并且我希望它具有9.png作为背景绘制。 这里是绘制:9patch可绘制为RelativeLayout背景问题

enter image description here

我得到什么:

enter image description here

正如你所看到的 - 有多余的空间。

这里我使用RGB颜色作为研究背景(和我多么希望它看起来9patch):

enter image description here

难道我做一些有趣的事情,或者是正常的9patch的样子吗?

代码为

<?xml version="1.0" encoding="utf-8"?> 
<RelativeLayout 
    xmlns:android="http://schemas.android.com/apk/res/android" 
    android:layout_width="fill_parent" 
    android:layout_height="fill_parent"> 
    <RelativeLayout 
    android:id="@+id/relativeTop" 
    android:layout_width="fill_parent" 
    android:layout_height="wrap_content" 
    <--THIS IS IT--> 
    android:background="@drawable/cap"> 
    <--THIS IS IT--> 
    <Button 
     android:id="@+id/btnSearchMainReset" 
     android:text="@string/btnSearchMainReset_text" 
     android:layout_height="wrap_content" 
     android:layout_width="wrap_content" 
     android:layout_alignParentRight="true" 
    /> 
    </RelativeLayout> 
    <ScrollView 
    android:layout_width="fill_parent" 
    android:layout_height="wrap_content" 
    android:layout_below="@id/relativeTop"> 
    <RelativeLayout 
     android:paddingLeft="5dp" 
     android:paddingRight="5dp" 
     android:layout_below="@id/relativeTop" 
     android:layout_width="fill_parent" 
     android:layout_height="wrap_content" 
     android:background="#FFFFFF"> 
     <Button 
     android:id="@+id/btnSearchMainSearch" 
     android:text="@string/btnSearchMainSearch_text" 
     android:textSize="20sp" 
     android:layout_height="wrap_content" 
     android:layout_width="wrap_content" 
     android:layout_centerHorizontal="true" 
     android:width="200dp" 
     /> 
     <RelativeLayout 
     android:id="@+id/relativeMain" 
     android:layout_below="@id/btnSearchMainSearch" 
     android:layout_width="fill_parent" 
     android:layout_height="fill_parent"> 
     <-- MULTIPLE VIEWS HERE --> 
     </RelativeLayout> 
     <Button 
     android:id="@+id/btnSearchMainSearchLow" 
     android:text="@string/btnSearchMainSearch_text" 
     android:textSize="20sp" 
     android:layout_height="wrap_content" 
     android:layout_width="wrap_content" 
     android:layout_centerHorizontal="true" 
     android:layout_below="@@id/relativeMain" 
     android:width="200dp" 
     /> 
    </RelativeLayout> 
    </ScrollView> 
</RelativeLayout> 
+1

后从您的布局XML – FoamyGuy 2011-05-13 16:33:23

+0

这是蒂姆的代码。 – 2011-05-13 16:46:11

+0

布局看起来不错。我肯定认为这是NinePatch的问题。 – OcuS 2011-05-13 16:46:56

回答

2

这是你的形象应该如何看,如果你想没有多余的空间更新。

image.9.png

看一看上Nine Patch Android文档;尤其要注意可伸缩区域和填充框。该图像使用右侧和顶部边缘上给出的数据像素定义填充。

九补丁是所有关于逻辑和图形编程,它可以在一开始很迷惑......

+0

使用渐变时,如果您将其拉伸超过1个像素,它将在某些设备上变形。在draw9patch应用程序中有一个“显示错误的修补程序”按钮,它会为您突出显示。当然,如果只拉伸一个像素,那么视图的中心只会有1个颜色,并且只会在边缘上渐变渐变。 – FoamyGuy 2011-05-13 17:28:59