2014-02-19 35 views
0

我在我的Android應用程序中有9修補圖像的一些weired問題。9貼片PNG不想舒展

我想用簡單的png在屏幕上劃一條線。從它創建9修補程序後,我只是將其作爲可擴展的容器添加到ImageView容器中。不幸的是,它不想伸展,仍然有這樣的昏暗。因爲我從來沒有使用過9-patch png,所以我不知道我在做什麼錯誤,而且在Google中搜索並不是那麼有用,因爲只有信息,如何製作一個,現在如何使用它。

這是xml文件我的代碼片段:

<ImageView 
android:layout_width="fill_parent" 
android:layout_height="wrap_content" 
android:src="@drawable/testpng" /> 

,這是一個像我想補充: enter image description here

回答

0

我找到了我的問題的答案。缺少的是一行代碼android:scaleType="fitXY"

現在它看起來像這樣

<ImageView 
android:layout_width="fill_parent" 
android:layout_height="wrap_content" 
android:scaleType="fitXY" 
android:src="@drawable/testpng" /> 
2

好吧,如果它只是一個簡單的線條,你就不需要9補丁...
只需使用一個視圖,給它一個顏色作爲背景,並給它一個1個像素尺寸:

<!-- Horizontal line --> 
<View 
    android_layout_width="match_parent" 
    android_layout_height="1px" 
    android:background="#ffff" 
/> 

<!-- Vertical line --> 
<View 
    android_layout_width="1px" 
    android_layout_height="match_parent" 
    android:background="#ffff" 
/> 

對於陰影線:

我使用它,以便:

<View 
    android:layout_width="match_parent" 
    android:layout_height="2px" 
    android:layout_centerVertical="true" 
    android:background="@drawable/line_h" 
/> 

,這是line_h.9png,小如我可以使它(6 * 4像素))

enter image description here

現在,這並不顯示在我的圖形佈局編輯器中,但它在運行時會顯示!

+0

好,但有一個影子也用它。這是相當複雜的,我猜 – sebap123

+0

我試圖改變高度來修復價值和沒有發生(除了身高增加) – sebap123

+0

讓我看看...我要修復你的9補丁,回來... –

1

檢查您的文件的擴展名是.9.png。如果不是,則不會將其識別爲9補丁。