OGeek|极客世界-中国程序员成长平台

标题: 使用 Glide 的圆形配置文件图片的 Android 边框 [打印本页]

作者: 菜鸟教程小白    时间: 2022-12-9 06:49
标题: 使用 Glide 的圆形配置文件图片的 Android 边框

问题已解决,请查看下面的答案以了解情况


我正在尝试创建从 Facebook 帐户下载的个人资料图片的边框。但是即使在学习了stackoverflow的其他示例之后,我也无法正确地做到这一点。正在使用 Glide 库下载个人资料图片。这是我的代码:-

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);
            }
        });

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

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

这是我从上面的代码中得到的结果:-

5.7inch Phone{Real Phone} enter image description here

在 5.5 英寸手机中{Emulator}

enter image description here



Best Answer-推荐答案


所以,我已经解决了这个问题,我的代码使用椭圆是 100% 正确的。

我所做的是我将图像固定为 90dp 的相对布局,这使得它变得不合适,当我纠正它以包装内容时,它非常适合。附上快照供其他人引用。

enter image description here

关于使用 Glide 的圆形配置文件图片的 Android 边框,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46675305/






欢迎光临 OGeek|极客世界-中国程序员成长平台 (https://www.ogeek.cn/) Powered by Discuz! X3.4