1.自定义InfoWindowAdapter:

package com.onetoo.www.onetoo.abapter.home;import android.content.Context;import android.view.LayoutInflater;import android.view.View;import android.widget.ImageView;import android.widget.TextView;import com.amap.api.maps2d.AMap;import com.amap.api.maps2d.model.Marker;import com.bumptech.glide.Glide;import com.onetoo.www.onetoo.R;import com.onetoo.www.onetoo.bean.home.HomeStore;import com.onetoo.www.onetoo.utils.StoreInfoUtil;/** * Created by longShun on 2016/11/3. * desc自定义地图信息框 */public class CustomInfoWindowAdapter implements AMap.InfoWindowAdapter{    private Context context;    public CustomInfoWindowAdapter(Context context) {        this.context = context;    }    @Override    public View getInfoWindow(Marker marker) {        View view = LayoutInflater.from(context).inflate(R.layout.map_info_window, null);        setViewContent(marker,view);        return view;    }    //这个方法根据自己的实体信息来进行相应控件的赋值     private void setViewContent(Marker marker,View view) {        //实例:        HomeStore.DataEntity storeInfo = (HomeStore.DataEntity) marker.getObject();        ImageView ivPic = (ImageView) view.findViewById(R.id.iv_info_store_pic);        Glide.with(context).load(storeInfo.getStore_pic()).centerCrop().into(ivPic);        TextView tvName = (TextView) view.findViewById(R.id.tv_info_store_name);        tvName.setText(storeInfo.getStore_name());        TextView tvType = (TextView) view.findViewById(R.id.tv_info_store_type);        String storeCategory = StoreInfoUtil.getStoreCategory(storeInfo.getFk_category_id());        tvType.setText(storeCategory);    }    //提供了一个给默认信息窗口定制内容的方法。如果用自定义的布局,不用管这个方法。    @Override    public View getInfoContents(Marker marker) {        return null;    }}

2.拿到AMap对象,设置adapter:

AMap aMap = mapView.getMap();aMap.setInfoWindowAdapter(new CustomInfoWindowAdapter(getActivity()));

3.Activity或则其他地方关键代码:

        MarkerOptions options = new MarkerOptions();                options.title("");//title不设infowindow不显示                options.position(new LatLng(latitude, longitude)).icon(BitmapDescriptorFactory                        .fromBitmap(BitmapFactory                                .decodeResource(getResources(), R.drawable.xxx)));        Marker marker = aMap.addMarker(options);        marker.setObject(object);//把相应的对象赋给marker,adapter中通过这个对象给控件赋值        aMap.setOnMarkerClickListener(this);        @Override        public boolean onMarkerClick(Marker marker) {            curShowWindowMarker = marker;//保存当前点击的Marker,以便点击地图其他地方设置InfoWindow消失            return false;//返回true,消费此事件。        }        aMap.setOnInfoWindowClickListener(this);        @Override        public void onInfoWindowClick(Marker marker) {            // TODO: 2016/11/3        }        aMap.setOnMapTouchListener(this);        @Override        public void onTouch(MotionEvent motionEvent) {             if (aMap != null && curShowWindowMarker != null) {                    if (curShowWindowMarker.isInfoWindowShown()){                        curShowWindowMarker.hideInfoWindow();               }            }        }

更多相关文章

  1. 【Android】数据库 sqLite
  2. Android的SharedPreferences(用于保存系统设置)
  3. android studio中rendering problems解决方法
  4. android 利用startActivityForResult()方法得到另一个Activity的
  5. Android自动化工具Monkeyrunner使用(六) —— 根据ID查找对象
  6. 浅谈Java中Collections.sort对List排序的两种方法
  7. 箭头函数的基础使用
  8. 类和 Json对象
  9. Python list sort方法的具体使用

随机推荐

  1. Android模拟器常用使用,和基本功能使用
  2. Android(安卓)View 绘制过程
  3. Android可拖拽布局ConstraintLayout
  4. (一)Android官方MVVM框架实现组件化之整
  5. Android(安卓)NDK开发之旅28--C++--vecto
  6. android 自定义Adapter的心得
  7. Android 性能优化的一些方法(转)
  8. Android Message和obtainMessage的区别
  9. Android(安卓)JiaoZiVideoPlayer源码分析
  10. Android开发效率的小技巧