how to fit in circular imageView?

10,570

Solution 1

if you are using Android studio please add this dependency

dependencies {
...
compile 'de.hdodenhof:circleimageview:2.1.0'}

then use this on your layout

<de.hdodenhof.circleimageview.CircleImageView
xmlns:app="http://schemas.android.com/apk/res-auto"
android:id="@+id/profile_image"
android:layout_width="96dp"
android:layout_height="96dp"
android:src="@drawable/profile"
app:civ_border_width="2dp"
app:civ_border_color="#FF000000"/>

this will help you

Solution 2

Updated dependencies

compile 'de.hdodenhof:circleimageview:2.1.0'

Border Color White using this and set width according to your need

app:border_color="@color/white"

app:border_width="1dp"

<de.hdodenhof.circleimageview.CircleImageView
     android:id="@+id/user_profile_image"
     android:layout_width="95dp"
     android:layout_height="95dp"
     android:layout_gravity="center"
     android:src="@mipmap/avatar_male"
     app:border_color="@color/white"
     app:border_width="1dp"
    />

enter image description here

Share:
10,570
ghasem deh
Author by

ghasem deh

Updated on December 01, 2022

Comments

  • ghasem deh
    ghasem deh about 1 month

    i use circular image_View in my app , but when select image for image_View image not fit to image_View

    this image_View : (xml)

    <ImageView
            android:id="@+id/user_profile_pic"
            android:layout_width="120dp"
            android:layout_height="120dp"
            android:layout_below="@+id/user_cover_pic"
            android:layout_centerHorizontal="true"
            android:layout_marginTop="-60dp"
            android:background="@drawable/circular_border"
            android:elevation="6dp"
            android:scaleType="centerCrop"
            android:padding="10dp"
            android:src="@drawable/ghasem"
            tools:ignore="ContentDescription,UnusedAttribute" />
    

    this circular border :

    <
    
    ?xml version="1.0" encoding="utf-8"?>
    <shape xmlns:android="http://schemas.android.com/apk/res/android"
        android:shape="rectangle">
        <corners android:radius="100dp" />
        <solid android:color="#fff" />
        <stroke
            android:width="3dip"
            android:color="@color/colorAccent" />
        <padding
            android:bottom="4dp"
            android:left="4dp"
            android:right="4dp"
            android:top="4dp" />
    </shape>
    

    enter image description here

    • Abhi
      Abhi almost 6 years
      Do you want to use only code or you are ok with library too? If you are ok with library may I suggest using this library, helped me a lot.
    • Rosário Pereira Fernandes
      Rosário Pereira Fernandes almost 6 years
      Have you tried android:scaleType="fitXY" ?
    • Manoj Perumarath
      Manoj Perumarath almost 4 years
      Possible duplicate of ImageView in circular through xml