2011-08-23 77 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

相关问题