I found one easy and simple solution for add border over imageview in which color want to set or add gradient over image.
STEPS:
imgPlaceHolder
, you need one white image or color which you want to set. <ImageView
android:id="@+id/imgPlaceHolder"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_gravity="center"
android:src="@drawable/white_bg"/>
<ImageView
android:id="@+id/imgPic"
android:layout_width="190dp"
android:layout_height="190dp"
android:layout_gravity="center"
android:src="@drawable/image01"/>
</FrameLayout>
After placing this code on xml file , put below line in java file.
Glide.with(this).load(R.drawable.image01).asBitmap().centerCrop().into(new BitmapImageViewTarget(imgPic) {
@Override
protected void setResource(Bitmap resource) {
RoundedBitmapDrawable circularBitmapDrawable =
RoundedBitmapDrawableFactory.create(getResources(), resource);
circularBitmapDrawable.setCircular(true);
imageView.setImageDrawable(circularBitmapDrawable);
}
});
Glide.with(this).load(R.drawable.white_bg).asBitmap().centerCrop().into(new BitmapImageViewTarget(imgPlaceHolder) {
@Override
protected void setResource(Bitmap resource) {
RoundedBitmapDrawable circularBitmapDrawable =
RoundedBitmapDrawableFactory.create(getResources(), resource);
circularBitmapDrawable.setCircular(true);
imgTemp2.setImageDrawable(circularBitmapDrawable);
}
});
This will make border of imageview simply with out any extra padding and margin.
NOTE : White image is compulsory for border otherwise it will not work.
Happy codding :)