android - 如何使用滑动调整占位符可绘制图像的大小?
问题描述
我从 git 和 stackoverflow 尝试了很多答案,但我没有找到正确的解决方案。
我在gridview中使用了滑翔。在xml中
<SquareRelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="@+id/people_raw_relative_layout">
<ImageView
android:id="@+id/people_raw_thumbnail"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_alignParentStart="true"
android:layout_alignParentTop="true"
android:layout_marginStart="1dp"
android:layout_marginEnd="1dp"
android:layout_marginBottom="2dp"
android:background="?attr/appBackground"
android:scaleType="centerCrop"/>
</SquareRelativeLayout>
在onBindViewHolder
GlideApp.with(mContext).load(currentThumb).placeholder(R.drawable.people_image_loading_ppa).transition(DrawableTransitionOptions.withCrossFade(1000))
.apply(new RequestOptions()
.diskCacheStrategy(DiskCacheStrategy.AUTOMATIC)
.skipMemoryCache(true)
.dontTransform()
.fitCenter()
.priority(Priority.IMMEDIATE)
.encodeFormat(Bitmap.CompressFormat.PNG)
.format(DecodeFormat.DEFAULT)).into(peopleViewHolder.imageView);
我的drawable是
<animated-rotate
xmlns:android="http://schemas.android.com/apk/res/android"
android:drawable="@drawable/people_image_loading_spinner"
android:pivotX="50%"
android:pivotY="50%"
/>
我想在不更改原始图像比例类型(centerCrop)的情况下调整占位符大小。问题是占位符(加载条图像)目前也在中心裁剪中,如下图所示。我想要这个加载栏 30x30 dp 在 imageview 的中心
解决方案
在 Glide 4.x 版本中,您可以通过 apply() 添加 RequestOptions
Glide
.with(context)
.load(path)
.apply(new RequestOptions().override(600, 200))
.into(imageViewResizeCenterCrop);
推荐阅读
- c# - 将多个实体写入数据库时哪个更快:Add() 循环添加每个项目或 AddRange() 添加对象列表?
- java - HashSet 内部使用 HashMap。在 HashMap 中,如果我们尝试放入相同的键,则会覆盖先前的值
- bash - 如何编写一个bash脚本代码来显示当月的星期六和星期日的日期
- r - 使用基础 R 进行过滤和排序不起作用
- c - 在 docker 容器中使用 membarrier
- angular - 无法在角度服务中的 Observable 中使用 Promise
- java - Git 子模块和包
- javascript - 如何设置字段以匹配 Flowjs 中的数组值?
- django - 如何为 html 文件启用 cors?
- java - 应用程序被杀死时 FCM onMessageReceived 不会触发(Android Oreo)