0

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);
Muneeb Ali
  • 472
  • 6
  • 14
Chirila Vasile
  • 359
  • 1
  • 2
  • 11
  • Try this one `https://stackoverflow.com/a/5651242/9792247` – Prayag Gediya Aug 21 '19 at 12:35
  • Yeah, that's to be expected for `CardView`. I'm not sure how your `DownloadImageView` works, exactly, but you could probably use `RoundedBitmapDrawableFactory` to get a `RoundedBitmapDrawable` from your image/stream, then draw that to your new `Bitmap`. Don't forget to `setBounds()` on the `RoundedBitmapDrawable`. – Mike M. Aug 21 '19 at 12:37
  • @MikeM. could you post your comment as an answer. Will it be any different if for example, you have a LinearLayout with two children: CardView and Some other View. When you createBitmap from LinearLayout, it just ignores all the rouned corners of CardView. – musooff Jun 17 '20 at 07:54
  • @MikeM. I know it has been a long time, but this question has not been answered and it looks like you have got an answer for it. – musooff Jun 17 '20 at 07:55
  • @musooff Are you using Picasso, like the OP here? I don't think I ever noticed that they mentioned that, because I'm pretty sure there's some way to have Picasso round the resulting `Bitmap` for you already. I would've recommended they try that, first. – Mike M. Jun 17 '20 at 08:09
  • @MikeM. I believe it has nothing to do with Picasso. I have random views inside my CardView. Some just simple TextView or ImageView. Say in the case of TextView inside CardView, if I set some high radius (100dp) it works fine while showing. TextView will get cut and be inside rounded corners. But when I create bitmap. I get an image that behaves as if there was no CardView. No rounding. No TextView is got cut. – musooff Jun 17 '20 at 08:55
  • @musooff That's slightly different than what the OP here was asking. They're basically dealing with a single `ImageView` and image, which is why I would've suggested letting Picasso handle it. In your case, yeah, you'd have to handle that yourself directly. You could still possibly make use of `RoundedBitmapDrawable`, to simplify things. You'd need to first `draw()` the `CardView`/`TextView` to a `Bitmap` with a `Canvas`, create a `RoundedBitmapDrawable` from that `Bitmap`, then draw that to the destination `Bitmap`. There are other ways, too, certainly. – Mike M. Jun 17 '20 at 09:08
  • @MikeM. for the sake of showing some visuals, I created a [room](https://chat.stackoverflow.com/rooms/216124/room-for-musooff-and-mike-m) – musooff Jun 17 '20 at 09:13

0 Answers0