0

I have an CardView with ImageView:

<android.support.v7.widget.CardView
        android:id="@+id/message_avatar_card"
        android:layout_width="40dp"
        android:layout_height="40dp"
        android:layout_marginEnd="4dp"
        android:layout_marginStart="4dp"
        app:cardCornerRadius="40dp"
        android:innerRadius="0dp"
        android:thicknessRatio="1.9"
        android:background="@color/fui_transparent">

        <ImageView
            android:id="@+id/message_avatar"
            android:layout_width="40dp"
            android:layout_height="40dp"
            android:src="@drawable/ic_person_black_24dp"
            android:layout_marginEnd="4dp"
            android:scaleType="centerCrop"
            android:background="@color/fui_transparent"/>
    </android.support.v7.widget.CardView>

On Android 9.0 all is ok, see screenshot

android 9

But on Android 5.1 I see rhombus , not circle

android 5.1

How to fix it?

2 Answers2

0

Right code

<android.support.v7.widget.CardView
        android:id="@+id/message_avatar_card"
        android:layout_width="40dp"
        android:layout_height="40dp"
        android:layout_marginEnd="4dp"
        android:layout_marginStart="4dp"
        app:cardCornerRadius="20dp"
        android:innerRadius="0dp"
        android:thicknessRatio="1.9"
        android:background="@color/fui_transparent">

        <ImageView
            android:id="@+id/message_avatar"
            android:layout_width="40dp"
            android:layout_height="40dp"
            android:src="@drawable/ic_person_black_24dp"
            android:layout_marginEnd="4dp"
            android:scaleType="centerCrop"
            android:background="@color/fui_transparent"/>
    </android.support.v7.widget.CardView>
0

Use CircleImageView library :

implementation 'de.hdodenhof:circleimageview:2.2.0'

in XML :

<de.hdodenhof.circleimageview.CircleImageView
        xmlns:app="http://schemas.android.com/apk/res-auto"
        android:id="@+id/message_avatar"
        android:layout_width="75dp"
        android:layout_height="75dp"
        android:src="@drawable/avatar"
        app:civ_border_width="2dp"
        android:layout_gravity="center"
        app:civ_border_color="YOUR_COLOR"/> // if you don't want give any border remove this line

In java :

CircleImageView message_avatar = (CircleImageView) findViewById(R.id.message_avatar);

if you are set image dynamically use Picasso library:

implementation 'com.squareup.picasso:picasso:2.5.2'

in Java

Picasso.with(context).load(IMAGE_PATH).into(message_avatar);
Abhinav Gupta
  • 2,225
  • 1
  • 14
  • 30