In my app, I need to work with GoogleMap and on Markers, I need to put the next custom view
<android.support.v7.widget.CardView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:clipChildren="true"
android:layout_margin="1dp"
android:elevation="10dp"
app:cardCornerRadius="18dp">
<app.into.additional.DownloadImageView
android:id="@+id/offer_image_1"
android:scaleType="fitXY"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_margin="1dp" />
</android.support.v7.widget.CardView>
DownloadImageView
is a custom class that uses the Picasso
framework to download some images.
The problem is the next one: if I add the above layout in a fragment, the ImageView is rounded as I need. When I try to create a Bitmap
using the above layout, the Image
loaded inside ImageView
doesn't keep the round property, and it's shows square.
This is the code I'm using to create the Bitmap
:
DisplayMetrics displayMetrics = new DisplayMetrics();
activity.getWindowManager().getDefaultDisplay().getMetrics(displayMetrics);
marker.setLayoutParams(new RelativeLayout.LayoutParams(RelativeLayout.LayoutParams.WRAP_CONTENT, RelativeLayout.LayoutParams.WRAP_CONTENT));
marker.measure(displayMetrics.widthPixels, displayMetrics.heightPixels);
marker.layout(0, 0, displayMetrics.widthPixels, displayMetrics.heightPixels);
marker.buildDrawingCache();
Bitmap bitmap = Bitmap.createBitmap(marker.getMeasuredWidth(), marker.getMeasuredHeight(), Bitmap.Config.ARGB_4444);
Canvas canvas = new Canvas(bitmap);
marker.draw(canvas);