首先,这是我的回收站视图的项目布局
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/root_layout"
android:layout_width="wrap_content"
android:layout_height="wrap_content">
<TextView
android:id="@+id/title"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:fontFamily="@font/roboto_medium"
android:maxLines="3"
android:text="dddddddddddddddddddddddddddddddddddddd"
android:textColor="@color/tab_text_color"
android:textSize="@dimen/_14ssp"
app:layout_constraintEnd_toEndOf="@+id/cardView17"
app:layout_constraintStart_toStartOf="@+id/cardView17"
app:layout_constraintTop_toBottomOf="@+id/cardView17" />
<androidx.cardview.widget.CardView
android:id="@+id/cardView17"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="4dp"
android:layout_marginTop="8dp"
android:layout_marginEnd="4dp"
app:cardCornerRadius="@dimen/_6sdp"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent">
<androidx.constraintlayout.widget.ConstraintLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content">
<ImageView
android:id="@+id/thumbnail"
android:layout_width="@dimen/_120sdp"
android:layout_height="@dimen/_180sdp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:srcCompat="@drawable/edit_bg" />
</androidx.constraintlayout.widget.ConstraintLayout>
</androidx.cardview.widget.CardView>
</androidx.constraintlayout.widget.ConstraintLayout>
这就是我添加微光效果的方式
val shimmer = Shimmer.AlphaHighlightBuilder()// The attributes for a ShimmerDrawable is set by this builder
.setDuration(2000) // how long the shimmering animation takes to do one full sweep
.setBaseAlpha(0.9f) //the alpha of the underlying children
.setHighlightAlpha(0.93f) // the shimmer alpha amount
.setWidthRatio(1.5F)
.setDirection(Shimmer.Direction.LEFT_TO_RIGHT)
.setAutoStart(true)
.build()
val shimmerDrawable = ShimmerDrawable().apply {
setShimmer(shimmer)
}
Glide
.with(context)
.load(data.thumbnail)
.placeholder(shimmerDrawable)
.diskCacheStrategy(DiskCacheStrategy.NONE)
.skipMemoryCache(true)
.centerCrop()
.into(binding.thumbnail)
这就是我得到的结果
是的,微光效果工作正常,下载图像时也会加载图像,但在微光效果期间,我得到了这些奇怪的后边缘,我试图在上述布局中更改某些视图的背景颜色,但没有任何效果,如果我删除微光效果和占位符,那么就没有边缘,显然也没有微光