[英]Android Border of Circular Profile Pic using Glide
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. 我正在尝试创建从Facebook帐户下载的个人资料图片的边框。 But I am not able to do it correctly even after studying the other examples here at stackoverflow.
但即使在stackoverflow上研究其他示例之后,我也无法正确执行此操作。 The profile picture is being downloaded using Glide library.
正在使用Glide库下载个人资料图片。 Here's my code :-
这是我的代码: -
Glide library Code in Java Java中的Glide库代码
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 XML中的ImageView
<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 在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} 在5.7英寸电话{真正的电话}
in 5.5inch phone{Emulator} 在5.5英寸手机{模拟器}
So, I have solved the issue, my code is 100% correct using oval. 所以,我已经解决了这个问题,我的代码使用椭圆100%正确。
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. 我所做的是相对布局,我把它的图像固定为90dp这使得它不合适,一旦我纠正它以包装内容,它是非常合适的。 Snapshot attached for reference for other people.
附上快照供其他人参考。
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" >
You can Create an xml file and setBackground for ImageView or use the library in github with code 您可以为ImageView创建xml文件和setBackground,或者使用github中的库和代码
<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"
/>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.