如何在 glide 4 中为圆形裁剪图像制作阴影
How to make shadow for circle cropped image in glide 4
我在 glid4 中使用 RoundedCorners
方法制作的个人资料图片非常扁平,我的个人资料没有任何阴影。我如何为我的图像配置文件设置阴影?glid4 对此有任何方法,或者我必须创建一个?
替代解决方案:-
使用自定义可绘制对象并将其设置为图像视图背景shadow.xml
<?xml version="1.0" encoding="utf-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
<item>
<shape android:shape="oval">
<solid android:color="@color/gray"/>
<!--shadow Color-->
</shape>
</item>
<item
android:left="0dp"
android:right="0dp"
android:top="0dp"
android:bottom="3dp">
<shape android:shape="oval">
<solid android:color="@color/lightgrey"/>//your background color here
</shape>
</item>
</layer-list>
这样使用:-
android:background="@drawable/shadow"
您可以尝试的另一种解决方案:-
https://github.com/Pkmmte/CircularImageView
这个库可以满足您的要求
实施"com.github.bumptech.glide:glide:4.10.0"
XML
<FrameLayout
android:id="@+id/fl_image"
android:layout_width="60dp"
android:layout_height="60dp"
android:layout_margin="10dp"
android:background="@drawable/card_circle_background"
android:elevation="8dp">
<ImageView
android:id="@+id/iv_item_employee"
android:layout_width="60dp"
android:layout_height="60dp"
tools:background="@color/colorPrimary" />
</FrameLayout>
形状可绘制
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="oval">
<solid android:color="@color/white"/>
</shape>
滑行配置
Glide.with(this)
.asBitmap()
.load(item.image)
.apply(RequestOptions.circleCropTransform())
.into(iv_item_employee)
我在 glid4 中使用 RoundedCorners
方法制作的个人资料图片非常扁平,我的个人资料没有任何阴影。我如何为我的图像配置文件设置阴影?glid4 对此有任何方法,或者我必须创建一个?
替代解决方案:-
使用自定义可绘制对象并将其设置为图像视图背景shadow.xml
<?xml version="1.0" encoding="utf-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
<item>
<shape android:shape="oval">
<solid android:color="@color/gray"/>
<!--shadow Color-->
</shape>
</item>
<item
android:left="0dp"
android:right="0dp"
android:top="0dp"
android:bottom="3dp">
<shape android:shape="oval">
<solid android:color="@color/lightgrey"/>//your background color here
</shape>
</item>
</layer-list>
这样使用:-
android:background="@drawable/shadow"
您可以尝试的另一种解决方案:- https://github.com/Pkmmte/CircularImageView
这个库可以满足您的要求
实施"com.github.bumptech.glide:glide:4.10.0"
XML
<FrameLayout
android:id="@+id/fl_image"
android:layout_width="60dp"
android:layout_height="60dp"
android:layout_margin="10dp"
android:background="@drawable/card_circle_background"
android:elevation="8dp">
<ImageView
android:id="@+id/iv_item_employee"
android:layout_width="60dp"
android:layout_height="60dp"
tools:background="@color/colorPrimary" />
</FrameLayout>
形状可绘制
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="oval">
<solid android:color="@color/white"/>
</shape>
滑行配置
Glide.with(this)
.asBitmap()
.load(item.image)
.apply(RequestOptions.circleCropTransform())
.into(iv_item_employee)