Issue
I have a MapView that works properly and is setup, the overlay items being drawn (when simply referenced as a drawable) work just fine. However, each drawable item needs to include a numerical value on it (e.g, overlay item 1, needs to display a #1 on it). I created the layout style R.layout.map_bubble_standard. I'm trying to convert that view into a bitmap, and that bitmap into a drawable to be displayed on the map. However, when the map loads, nothing shows up. Here's what I'm doing...
LayoutInflater inflater = (LayoutInflater) _context.getSystemService( Context.LAYOUT_INFLATER_SERVICE );
LinearLayout bubbleView = (LinearLayout)inflater.inflate(R.layout.map_bubble_standard, null);
bubbleView.setDrawingCacheEnabled(true);
bubbleView.buildDrawingCache();
//drawable = _context.getResources().getDrawable(R.drawable.map_pin_48);
drawable = new BitmapDrawable(_context.getResources(), bubbleView.getDrawingCache());
bubbleView.setDrawingCacheEnabled(false);
OverlayItem oi = _overlays.get(whichOne);
oi.setMarker(boundCenterBottom(drawable));
My code completes the method just fine, but nothing is drawn on the map. Can anyone help determine what I'm doing incorrectly?
[Edit] - Resolved
I used a another link that I found, that offered advice for fixing this: Here
Hopefully this can help someone else out in the future as well. For reference, I also moved the inflater for the view and the inflater object itself into the default constructor for my itemized overlay class.
_bubbleLayout.setDrawingCacheEnabled(true);
_bubbleLayout.measure(MeasureSpec.makeMeasureSpec(0, MeasureSpec.UNSPECIFIED),
MeasureSpec.makeMeasureSpec(0, MeasureSpec.UNSPECIFIED));
_bubbleLayout.layout(0, 0, _bubbleLayout.getMeasuredWidth(), _bubbleLayout.getMeasuredHeight());
_bubbleLayout.buildDrawingCache(true);
Bitmap b = Bitmap.createBitmap(_bubbleLayout.getDrawingCache());
_bubbleLayout.setDrawingCacheEnabled(false); // clear drawing cache
//drawable = _context.getResources().getDrawable(R.drawable.map_pin_48);
drawable = (Drawable) new BitmapDrawable(_context.getResources(),b);
OverlayItem oi = _overlays.get(whichOne);
oi.setMarker(boundCenterBottom(drawable));
Solution
Not sure if this is right, but according to the documentation:
To benefit from the cache, you must request the drawing cache by calling getDrawingCache() and draw it on screen if the returned bitmap is not null.
To me that means you must have drawn the View once on the screen before you get anything back. If its never been actually drawn then it has no cache to pull from. Are you making this visible on the screen first?
Answered By - Salil Pandit
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.