2011-08-23 70 views
1

我嘗試爲GoogleMaps實現Map View balloon,但我阻止了氣球的佈局。
氣球的大小必須是內容大小,但是,它需要背景可繪製大小,因爲它的大小較大。由於我有一個相當大的氣球9-patch image,由其他人提供,一個小型氣球內容需要所有的屏幕(可繪製的大小)。如何包裝內容視圖而不是後臺可繪製?

只見此相關的問題:How to wrap content views rather than background drawable?,這正是我想要的,但它沒有正確的答案(使用FrameLayout作出了同樣的問題,因爲ImageView SRC將採取繪製尺寸也與wrap_contentfill_parent) 。

這裏是我的佈局:

<?xml version="1.0" encoding="utf-8"?> 
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    android:layout_height="wrap_content" android:id="@+id/balloon_main_layout" 
    android:orientation="horizontal" android:clickable="true" 
    android:focusable="true" android:focusableInTouchMode="true" 
    android:layout_width="wrap_content" android:background="@drawable/info_bulle_selector"> 
    <LinearLayout android:id="@+id/linearLayout1" 
     android:layout_height="wrap_content" android:layout_width="0dp" 
     android:layout_weight="1"> 
     <TextView android:layout_height="wrap_content" 
      android:layout_width="wrap_content" android:text="TextView" 
      android:id="@+id/balloon_item_title" android:textColor="#ffffff"></TextView> 
    </LinearLayout> 
    <ImageView android:id="@+id/balloon_close" 
     android:layout_marginLeft="5dp" android:src="@drawable/fermer_selector" 
     android:scaleType="fitXY" android:layout_height="30dp" 
     android:layout_width="30dp"></ImageView> 
</LinearLayout> 

這裏是什麼,我有一個屏幕(衝空間已被刪除):
Current baloon layout

如果您有任何想法來解決這個問題(當我用背景圖像設計我的佈局時,我經常會遇到這種情況),那會很棒。
在此先感謝。

編輯:
這裏九宮PNG: nine-patch balloon

回答

2

當我明白你的問題所在,你有兩個選擇:

1)使氣球9補丁圖像更小,尤其是9貼片圖像的不可伸縮區域和填充區域,因此可以更好地適應更小的內容。見這裏更多的文檔:http://developer.android.com/guide/topics/graphics/2d-graphics.html#nine-patch

編輯:

正如我在第1點通知),您的9補丁圖像太大。它的寬度爲330px,高度爲74px。由於您的內容不會填充整個背景圖片的寬度和高度,因此您的佈局中會有空格。

作爲一種可能的解決方案,請縮小9貼片圖像。我收縮你的圖像的寬度爲150px和34像素的高度,我得到了以下結果:

screen shows 3 balloons with different contents

這裏是萎縮9修補圖像: enter image description here

+0

是的,我認爲太第一個解決方案,但它是一種技巧,所以它不能解決一般問題,所以我想知道是否存在另一種解決方案。由於這個小三角形,第二個解決方案對於氣球來說並不好。但是,如果在接受您的解決方案之前還有其他答案,我會等待。 – Astrorvald

+0

你能上傳9貼片圖片嗎? – AZ13

+0

我用一個工作解決方案編輯了我的答案。 – AZ13

相關問題