如何在标记上添加线条和按钮? [关闭]

问题描述 投票:-1回答:1

当用户使用Marker类的片段点击标记时,我试图显示一些信息。据我所知,问题是它只能是1行,所以我不能添加新行来使信息更清晰。有没有办法显示多条单行? 我正在使用默认的MapActivity和googleMap API V2 提前感谢您的耐心和考虑。

java android marker mapactivity
1个回答
1
投票

您可以创建自定义信息窗口。看看这个码头https://developers.google.com/maps/documentation/android-sdk/infowindows#custom_info_windows

适配器示例:

public class CustomInfoWindow implements GoogleMap.InfoWindowAdapter {
    Context context; 
    LayoutInflater inflater;
    public CustomInfoWindow(Context context) {
           this.context = context;
    }
    @Override    
    public View getInfoContents(Marker marker) {        
        return null;    
    }
    @Override
    public View getInfoWindow(Marker marker) {
    inflater = (LayoutInflater)
context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);  

   // R.layout.custom_info_window is a layout
   // res/layout folder. You can provide your own
    View v = inflater.inflate(R.layout.custom_info_window, null);   

    TextView title = (TextView) v.findViewById(R.id.info_window_title);     
  TextView subtitle = (TextView) v.findViewById(R.id.info_window_subtitle);
    title.setText(marker.getTitle());
    subtitle.setText(marker.getSnippet());
    return v;
    }
}

为了使用它,你需要制作:map.setInfoWindowAdapter(new CustomInfoWindow(context));

© www.soinside.com 2019 - 2024. All rights reserved.