如何把绘制作为信息窗口(谷歌地图API V2为Android)的背景下? [英] How to put drawable as a background on InfoWindow (Google Maps API v2 for Android)?
本文介绍了如何把绘制作为信息窗口(谷歌地图API V2为Android)的背景下?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
这是我的自定义布局,我的信息窗口:
This is my custom layout for my info window:
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="@drawable/bg_infowindow" >
<LinearLayout
android:id="@+id/text_box"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="vertical" >
<TextView
style="@style/TexTitle"
android:id="@+id/title"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
<TextView
style="@style/TextDistance"
android:id="@+id/distance"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
</LinearLayout>
</RelativeLayout>
这是我的自定义适配器:
And this is my custom adapter:
public class MapInfoWindowAdapter implements InfoWindowAdapter{
private LayoutInflater inflater;
private Context context;
public MapInfoWindowAdapter(Context context){
inflater = (LayoutInflater) context.getSystemService( Context.LAYOUT_INFLATER_SERVICE );
this.context = context;
}
@Override
public View getInfoContents(Marker marker) {
// Getting view from the layout file
View v = inflater.inflate(R.layout.map_popup, null);
TextView title = (TextView) v.findViewById(R.id.title);
title.setText(marker.getTitle());
TextView address = (TextView) v.findViewById(R.id.distance);
address.setText(marker.getSnippet());
return v;
}
@Override
public View getInfoWindow(Marker arg0) {
// TODO Auto-generated method stub
return null;
}
}
这是结果:
但是我想自定义绘制至于我的信息窗口的唯一背景下,如何实现这一目标?
推荐答案
在 getInfoContents
替换codeS与 getInfoWindow
。它们之间的区别是 getInfoContents
包裹你的查看
在的ViewGroup
使用默认背景。
Replace codes in getInfoContents
with getInfoWindow
. The difference between them is getInfoContents
wraps your View
in ViewGroup
with default background.
@Override
public View getInfoWindow(Marker marker) {
// Getting view from the layout file
View v = inflater.inflate(R.layout.map_popup, null);
TextView title = (TextView) v.findViewById(R.id.title);
title.setText(marker.getTitle());
TextView address = (TextView) v.findViewById(R.id.distance);
address.setText(marker.getSnippet());
return v;
}
@Override
public View getInfoContents(Marker arg0) {
// TODO Auto-generated method stub
return null;
}
这篇关于如何把绘制作为信息窗口(谷歌地图API V2为Android)的背景下?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文