Android地图 – 使用布局作为叠加项

Android地图 – 使用布局作为叠加项,第1张

概述我在MapQuest提供的 Android中使用地图,但实施方式与Google地图相同,因此同样的问题也适用. 对于叠加项,我想使用带有ImageView和TextView的布局,因为TextView将显示一些信息.问题是我似乎只能显示一个drawable作为我的叠加层,它必须来自Drawable文件夹. 以下是添加叠加项的代码: private void loadSingleOverlay(Ta 我在mapquest提供的 Android中使用地图,但实施方式与Google地图相同,因此同样的问题也适用.

对于叠加项,我想使用带有ImageVIEw和TextVIEw的布局,因为TextVIEw将显示一些信息.问题是我似乎只能显示一个drawable作为我的叠加层,它必须来自Drawable文件夹.

以下是添加叠加项的代码:

private voID loadSingleOverlay(TapControlledMap mapVIEwPassed,String Title,String address){    Drawable icon = getResources().getDrawable(R.drawable.marker2);    OverlayItem newItem = new OverlayItem(point,Title,address);    overlay = new Extendeditemizedoverlay(icon);    overlay.addItem(newItem);    // add a tap Listener    overlay.setTapListener(tapListener);    List<Overlay> listofOverlays = mapVIEwPassed.getoverlays();    listofOverlays.clear();    listofOverlays.add(overlay);    mapVIEwPassed.invalIDate();}

我要扩充和使用的布局:

<?xml version="1.0" enCoding="utf-8"?><relativeLayout xmlns:androID="http://schemas.androID.com/apk/res/androID"    androID:layout_wIDth="match_parent"    androID:layout_height="match_parent" >    <ImageVIEw        androID:layout_wIDth="wrap_content"        androID:layout_height="wrap_content"        androID:src="@drawable/marker_red" />    <TextVIEw        androID:layout_wIDth="wrap_content"        androID:layout_height="wrap_content"        androID:text="1" /></relativeLayout>

这是我要去的结果:

谢谢大家

解决方法 这是不容易的.我知道的唯一方法是创建视图(例如,使用背景和文本视图的布局),然后将其渲染为位图.

public static Bitmap loadBitmapFromVIEw(VIEw v) {    displayMetrics dm = v.getContext().getResources().getdisplayMetrics();      Bitmap b = Bitmap.createBitmap(Math.round(v.getMeasureDWIDth() * dm.density),Math.round(v.getMeasuredHeight() * dm.density),Bitmap.Config.ARGB_8888);                        Canvas c = new Canvas(b);        v.draw(c);        return b;    }

然后,您可以使用下面的内容添加到地图中.您必须根据标记视图大小来调整边界.

Drawable d = new BitmapDrawable(Utils.loadBitmapFromVIEw(yourVIEw));        d.setBounds(-35,-30,Math.round(d.getIntrinsicWIDth() * dm.density) - 35,Math.round(d.getIntrinsicHeight() * dm.density) - 30);        overlayItem.setMarker(d);        overlayListVIEw.add(overlay);
总结

以上是内存溢出为你收集整理的Android地图 – 使用布局作为叠加项全部内容,希望文章能够帮你解决Android地图 – 使用布局作为叠加项所遇到的程序开发问题。

如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。

欢迎分享,转载请注明来源:内存溢出

原文地址:https://54852.com/web/1128616.html

(0)
打赏 微信扫一扫微信扫一扫 支付宝扫一扫支付宝扫一扫
上一篇 2022-05-30
下一篇2022-05-30

发表评论

登录后才能评论

评论列表(0条)

    保存