首页
学习
活动
专区
工具
TVP
发布
社区首页 >问答首页 >如何在InfoWindow (Google Maps API v2 for Android)上放置drawable作为背景?

如何在InfoWindow (Google Maps API v2 for Android)上放置drawable作为背景?
EN

Stack Overflow用户
提问于 2013-05-13 17:05:45
回答 3查看 11.2K关注 0票数 21

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

代码语言:javascript
复制
<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>

这是我的自定义适配器:

代码语言:javascript
复制
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;
    }

}

这就是结果:

然而,我想要自定义绘图作为我的信息窗口的唯一背景,如何实现这一点?

EN

回答 3

Stack Overflow用户

回答已采纳

发布于 2013-05-13 18:01:19

getInfoWindow替换getInfoContents中的代码。它们之间的区别是getInfoContentsViewGroup中使用默认背景包装您的View

代码语言:javascript
复制
@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;
}
票数 58
EN

Stack Overflow用户

发布于 2013-05-13 17:19:39

试试这个..。

custom_infowindow.xml

代码语言:javascript
复制
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">


<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#80000000" 
android:orientation="vertical">

<ImageView
    android:src="@drawable/ic_launcher"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content" 
    android:padding="10dp"/>

</LinearLayout> 

</LinearLayout>


googleMap.setInfoWindowAdapter(new InfoWindowAdapter() 
{

        public View getInfoWindow(Marker arg0)
        {
            View v = getLayoutInflater().inflate(R.layout.custom_infowindow, null);
            return v;
        }

        public View getInfoContents(Marker arg0) 
        {
           return null;
        }
    });
票数 0
EN

Stack Overflow用户

发布于 2019-05-24 16:44:18

除了被接受的答案之外,我还想提一下,如果您仍然想要信息窗口气泡,您可以使用this bubble layout library

然后,您可以将气泡布局设置为您正在膨胀的自定义布局中的路线视图的背景。

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/16518338

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档