2011-05-13 106 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