2013-08-23 157 views
0

我有一個9貼片圖片,我想要做的就是用它從應用中「分離」adMob廣告。我想在廣告所在的位置繪製一條淺藍色的線條。如何使用9修補程序?

這是9補丁:

enter image description here

我添加它來佈局ImageView的,這是XML代碼:

<ImageView 
    android:id="@+id/imageView1" 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:layout_above="@+id/adView" 
    android:layout_alignParentLeft="true" 
    android:layout_alignParentRight="true" 
    android:src="@drawable/ab_transparent_example" /> 

這是結果:

enter image description here

但是我想要得到的是9-補丁來獲得屏幕的大小,從屏幕的左邊到右邊製作一條完整的藍線。我從來沒有用過9-patch,我做錯了什麼?

回答

1

下圖是一個9補丁就是一個相當不錯的視覺解釋。至於你的具體問題,你應該設置9補丁作爲圖像的背景。

<ImageView 
    android:id="@+id/imageView1" 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:layout_above="@+id/adView" 
    android:layout_alignParentLeft="true" 
    android:layout_alignParentRight="true" 
    android:background="@drawable/ab_transparent_example" /> 

9-patch Diagram

+0

非常感謝你,工作就像一個魅力,也非常有用的9補丁文件解釋:) – Guy

0

首先,您需要知道的是,9貼片的圖像與其他任何圖像一樣,關於放置它的佈局。區別在於9-補丁圖像縮放。

在這種情況下,嘗試設置layout_width爲「fill_parrent」或「match_父」

<ImageView 
android:id="@+id/imageView1" 
android:layout_width="fill_parent" 
android:layout_height="wrap_content" 
android:layout_above="@+id/adView" 
android:layout_alignParentLeft="true" 
android:layout_alignParentRight="true" 
android:src="@drawable/ab_transparent_example" />