有 Java 编程相关的问题?

你可以在下面搜索框中键入要查询的问题!

java如何向标记添加行和按钮?

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


共 (1) 个答案

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