图片背景毛玻璃效果实现
1 依赖
// Glide
implementation("com.github.bumptech.glide:glide:4.16.0")
kapt("com.github.bumptech.glide:compiler:4.16.0")
implementation("jp.wasabeef:glide-transformations:4.3.0")
2 布局<com.google.android.material.card.MaterialCardViewxmlns:android="http://schemas.android.com/apk/res/android"xmlns:app="http://schemas.android.com/apk/res-auto"android:id="@+id/cardView"android:layout_width="match_parent"android:layout_height="match_parent"android:clipChildren="true"app:cardElevation="0dp"app:cardBackgroundColor="@color/transparent"app:cardPreventCornerOverlap="true"app:strokeWidth="0dp"><!-- 毛玻璃模糊背景 View --><ImageViewandroid:id="@+id/blurBackground"android:layout_width="match_parent"android:layout_height="match_parent"android:adjustViewBounds="true"android:background="@color/ui_background"android:scaleType="centerCrop" />//...内容布局
<com.google.android.material.card.MaterialCardView/>3 MainActivity代码 Glide.with(this@MainActivity)
// .load(R.drawable.screen)
// .diskCacheStrategy(DiskCacheStrategy.ALL) // 显式声明使用缓存策略
// .transform(
// BlurTransformation(25, 8),
// ColorFilterTransformation(Color.argb(120, 0, 0, 0)) // 直接在毛玻璃效果上加深色遮罩
// )
// .into(binding.blurBackground)