gpt4 book ai didi

ANDROID:如何为谷歌地图上的标记制作自定义 View (布局)

转载 作者:太空狗 更新时间:2023-10-29 15:39:31 27 4
gpt4 key购买 nike

如何为标记制作自定义 View 或如何制作自定义布局。像这样... enter image description here请看截图:

enter image description here

最佳答案

使用布局的 Google map 自定义标记

View markerView = ((LayoutInflater) getActivity()
.getSystemService(
getActivity().LAYOUT_INFLATER_SERVICE))
.inflate(R.layout.map_marker, null);

设置标记

 marker = map.addMarker(new MarkerOptions()
.position(latLng)
.title(strName)
.snippet(strStatus)
.icon(BitmapDescriptorFactory
.fromBitmap(createDrawableFromView(
getActivity(),
markerView))));

从 Drawable 创建位图

public static Bitmap createDrawableFromView(Context context, View view) {
DisplayMetrics displayMetrics = new DisplayMetrics();
((Activity) context).getWindowManager().getDefaultDisplay()
.getMetrics(displayMetrics);
view.setLayoutParams(new LayoutParams(LayoutParams.WRAP_CONTENT,
LayoutParams.WRAP_CONTENT));
view.measure(displayMetrics.widthPixels, displayMetrics.heightPixels);
view.layout(0, 0, displayMetrics.widthPixels,
displayMetrics.heightPixels);
view.buildDrawingCache();
Bitmap bitmap = Bitmap.createBitmap(view.getMeasuredWidth(),
view.getMeasuredHeight(), Bitmap.Config.ARGB_8888);

Canvas canvas = new Canvas(bitmap);
view.draw(canvas);

return bitmap;
}

关于ANDROID:如何为谷歌地图上的标记制作自定义 View (布局),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7823428/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com