NewProgrammer
NewProgrammer

Reputation: 21

which is the best way to create circular image view with border and shadow in android? (through xml or java code)?

I'm new in android and I want to create a circular image view with border and shadow. I searched on internet and I got couple of codes, but some of them are xml layout code and others in java. So can you please tell me which one is better to use? Thanks!

Upvotes: 1

Views: 908

Answers (1)

Zain-ul-Abideen
Zain-ul-Abideen

Reputation: 21

In your build.gradle File:

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

In XML:

<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"/>

Limitations:

  1. The ScaleType is always CENTER_CROP and you'll get an exception if you try to change it. This is (currently) by design as it's perfectly fine for profile images.
  2. Enabling adjustViewBounds is not supported as this requires an unsupported ScaleType
  3. If you use an image loading library like Picasso or Glide, you need to disable their fade animations to avoid messed up images. For Picasso use the noFade() option, for Glide use dontAnimate(). If you want to keep the fadeIn animation, you have to fetch the image into a Target and apply a custom animation yourself when receiving the Bitmap.
  4. Using a TransitionDrawable with CircleImageView doesn't work properly and leads to messed up images.

hdodenhof/CircleImageView

Upvotes: 2

Related Questions