0

I'm trying to create a map marker from a custom view that contains an image inside a CardView. In order to do this, I draw the view to a bitmap using Canvas.

The result is problematic: the markers show the image as a square. What could be causing the CardView lose its corner radius?

The following is my XML layout file for the marker's custom view:

<android.support.constraint.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="56dp"
    android:layout_height="69dp">

  <ImageView
      android:id="@+id/discovertab_marker_pin_imageview"
      android:layout_width="56dp"
      android:layout_height="69dp"
      app:layout_constraintBottom_toBottomOf="parent"
      app:layout_constraintEnd_toEndOf="parent"
      app:layout_constraintStart_toStartOf="parent"
      app:layout_constraintTop_toTopOf="parent"
      app:srcCompat="@drawable/mappingreen" />

  <android.support.v7.widget.CardView
      android:layout_width="50dp"
      android:layout_height="50dp"
      android:layout_marginEnd="3dp"
      android:layout_marginStart="3dp"
      android:layout_marginTop="3dp"
      app:cardBackgroundColor="@color/colorPrimary"
      app:cardCornerRadius="25dp"
      app:cardElevation="0dp"
      app:layout_constraintEnd_toEndOf="parent"
      app:layout_constraintStart_toStartOf="parent"
      app:layout_constraintTop_toTopOf="parent">

    <ImageView
        android:id="@+id/discovertab_marker_profile_imageview"
        android:layout_width="50dp"
        android:layout_height="50dp" />

  </android.support.v7.widget.CardView>
</android.support.constraint.ConstraintLayout>
Ugur
  • 148
  • 4
  • 11
  • are you creating the marker as a png or jpg – Kuti Gbolahan Mar 29 '18 at 12:20
  • wouldn't it be easier if you just make an image of what you are desgining and then just use that as the marker image ? – FreakyAli Mar 29 '18 at 13:08
  • Forgot to mention, the imageview is dynamic and it is used to indicate the content's picture at the marker location on the map. So using a static image won't help. @G.hakim – Ugur Mar 29 '18 at 14:46
  • did you try assigning a smaller corner radius ? – FreakyAli Mar 30 '18 at 04:43
  • Yes I tried, but the result is the same. @G.hakim – Ugur Mar 31 '18 at 07:16
  • I would like to know a little more about your approch for making this marker through xml last time i remember you cannot directly do that. – FreakyAli Mar 31 '18 at 17:59
  • I first inflate the view with the xml layout. Then I draw the view onto a canvas as explained in [this answer](https://stackoverflow.com/a/3036736/7146410). Once I get the bitmap, I set the map marker's icon with the required `BitmapDescriptor` parameter using `BitmapDescriptorFactory.fromBitmap(Bitmap b);`. Sorry for the delay. @G.hakim – Ugur Apr 03 '18 at 13:50
  • Did you try any other layout instead of constraint layout because your methodology seems to be fine – FreakyAli Apr 03 '18 at 15:18

0 Answers0