高德地图自定义infowindow窗口

首先给出官方api上关于 marker和  infowindow的自定义方法:



aMap.setOnMarkerClickListener(this);// 设置点击marker事件监听器
aMap.setInfoWindowAdapter(this);// 设置自定义InfoWindow样式


<span style="font-size:18px;">/**
	 * 监听自定义infowindow窗口的infocontents事件回调
	 */
	@Override
	public View getInfoContents(Marker marker) {
		if (radioOption.getCheckedRadioButtonId() != R.id.custom_info_contents) {
			return null;
		}
		View infoContent = getLayoutInflater().inflate(
				R.layout.custom_info_contents, null);
		render(marker, infoContent);
		return infoContent;
	}

	/**
	 * 监听自定义infowindow窗口的infowindow事件回调
	 */
	@Override
	public View getInfoWindow(Marker marker) {
		if (radioOption.getCheckedRadioButtonId() != R.id.custom_info_window) {
			return null;
		}
		View infoWindow = getLayoutInflater().inflate(
				R.layout.custom_info_window, null);

		render(marker, infoWindow);
		return infoWindow;
	}

	/**
	 * 自定义infowinfow窗口
	 */
	public void render(Marker marker, View view) {
		if (radioOption.getCheckedRadioButtonId() == R.id.custom_info_contents) {
			((ImageView) view.findViewById(R.id.badge))
					.setImageResource(R.drawable.badge_sa);
		} else if (radioOption.getCheckedRadioButtonId() == R.id.custom_info_window) {
			ImageView imageView = (ImageView) view.findViewById(R.id.badge);
			imageView.setImageResource(R.drawable.badge_wa);
		}
		String title = marker.getTitle();
		TextView titleUi = ((TextView) view.findViewById(R.id.title));
		if (title != null) {
			SpannableString titleText = new SpannableString(title);
			titleText.setSpan(new ForegroundColorSpan(Color.RED), 0,
					titleText.length(), 0);
			titleUi.setTextSize(15);
			titleUi.setText(titleText);

		} else {
			titleUi.setText("");
		}
		String snippet = marker.getSnippet();
		TextView snippetUi = ((TextView) view.findViewById(R.id.snippet));
		if (snippet != null) {
			SpannableString snippetText = new SpannableString(snippet);
			snippetText.setSpan(new ForegroundColorSpan(Color.GREEN), 0,
					snippetText.length(), 0);
			snippetUi.setTextSize(20);
			snippetUi.setText(snippetText);
		} else {
			snippetUi.setText("");
		}
	}</span>

需要做的工作,简单来讲,就是首先要给AMap设置Marker的点击监听 和infowindow自定义的回调监听;


然后在getInfoWindow 中加载你自定义的View对象,并返回;

API优先回调getInfoWindow ,如果返回的是null,会再回调getInfoContents;

这样设置完成后,点击marker,弹出的infowindow样式如下:


高德地图 android 设置完全自定义的InfoWindow_image0


外围始终有一个高德自带的气泡框,关于如何替换这个气泡框,翻了一遍高德的api,完全没有一点点提示。


然而,万万没想到!!!我还是修改掉了这个气泡!


方法简直简单的令人发指!!!


在你自定义的view布局xml文件中,将最外围的布局背景设置为透明!整个世界瞬间就变得美好了!


<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:background="@android:color/transparent"
    android:orientation="horizontal" >

    <LinearLayout
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:background="@color/yellow"
    	android:orientation="horizontal"
        android:gravity="center_vertical" >

        <TextView
            android:id="@+id/inforwindow_text"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:textSize="@dimen/inforwindow_dest_desc_textsize" />

        <Button
            android:id="@+id/inforwindow_btn"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_marginLeft="5dp"
            android:gravity="center"
            android:text="@string/inforwindow_btn_tips" />
</LinearLayout>

</LinearLayout>
  • 1
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值