因來源不同及價錢同需客制可變icon
先用layout設計
View map_icon = ((LayoutInflater) getSystemService(Context.LAYOUT_INFLATER_SERVICE)).inflate({layout id}, null); //圖示價錢 TextView txt_price = (TextView) map_icon.findViewById(R.id.txt_price); txt_price.setText("958"); //加到地圖 mMap.addMarker(new MarkerOptions() .position(latLng) .snippet(gPrice.getID()) .icon(BitmapDescriptorFactory.fromBitmap(createDrawableFromView(MapActivity.this, map_icon))));
將view繪製成圖
// Convert a view to bitmap public static Bitmap createDrawableFromView(Context context, View view) { DisplayMetrics displayMetrics = new DisplayMetrics(); ((Activity) context).getWindowManager().getDefaultDisplay().getMetrics(displayMetrics); view.setLayoutParams(new ViewGroup.LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.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; }
沒有留言:
張貼留言