gpt4 book ai didi

android - 如何将可绘制对象作为 InfoWindow(Android 版 Google Maps API v2)的背景?

转载 作者:IT老高 更新时间:2023-10-28 23:08:42 25 4
gpt4 key购买 nike

这是我的信息窗口的自定义布局:

<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>

这是我的自定义适配器:

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;
}

}

结果如下:

enter image description here

但是我希望自定义可绘制对象作为我的信息窗口的唯一背景,如何实现这一点?

最佳答案

getInfoContents 中的代码替换为 getInfoWindow。它们之间的区别在于 getInfoContents 将您的 View 包装在具有默认背景的 ViewGroup 中。

@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;
}

关于android - 如何将可绘制对象作为 InfoWindow(Android 版 Google Maps API v2)的背景?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16518338/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com