2

Issue Solved Check My Answer Below for Understanding


I am trying to create a border of the profile picture which is being downloaded from Facebook account. But I am not able to do it correctly even after studying the other examples here at stackoverflow. The profile picture is being downloaded using Glide library. Here's my code :-

Glide library Code in Java

Glide.with(Home.this).load(url).asBitmap().into(new BitmapImageViewTarget(profile_pic){
            @Override
            protected void setResource(Bitmap resource) {
                RoundedBitmapDrawable circular = RoundedBitmapDrawableFactory.create(getApplicationContext().getResources(),resource);
                circular.setCircular(true);
                profile_pic.setImageDrawable(circular);
            }
        });

ImageView in XML

<ImageView
        android:id="@+id/profile_pic"
        android:layout_width="wrap_content"
        android:layout_height="match_parent"
        android:src="@mipmap/ic_launcher"
        android:padding = "5dp"
        android:background="@drawable/profile_pic_border"/>

Drawing border in Drawable

<shape android:shape="oval"
xmlns:android="http://schemas.android.com/apk/res/android" >
<stroke
    android:width="5dp"
    android:color="#3e65b4"/>
<size android:height="50dp"
android:width="50dp"/>

Here's what I am achieving from above code :-

In 5.7inch Phone{Real Phone} enter image description here

in 5.5inch phone{Emulator}

enter image description here

Ravi Bhardwaj
  • 128
  • 1
  • 13

3 Answers3

2

So, I have solved the issue, my code is 100% correct using oval.

What I had done was the Relative Layout in which I had put that image was fixed to 90dp which was making it improper, as soon as I corrected that to wrap content, it was a great fit. Snapshot attached for reference for other people.

enter image description here

Ravi Bhardwaj
  • 128
  • 1
  • 13
1

On your drawable file, instead of use the oval shape, change it to ring shape to get a perfect circle, like this:

<shape android:shape="ring"
xmlns:android="http://schemas.android.com/apk/res/android" >
Natan Felipe
  • 164
  • 1
  • 4
-2

You can Create an xml file and setBackground for ImageView or use the library in github with code

<de.hdodenhof.circleimageview.CircleImageView
                                android:id="@+id/act_detail_job_img_company"
                                android:layout_width="match_parent"
                                android:layout_height="match_parent"
                                android:layout_centerHorizontal="true"
                                android:background="@android:color/transparent"
                                android:src="@drawable/user"
                                app:civ_border_color="#FFFFFFFF"
                                app:civ_border_width="2dp"
                                />
Doan Bui
  • 1,269
  • 11
  • 18