有一个ImageView元素,其高度和宽度具有wrap_content属性。
...
<ImageView
android:id="@+id/previewImageView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginBottom="@dimen/size_ssmall"
android:adjustViewBounds="true"
android:visibility="gone"
app:layout_constraintBottom_toTopOf="@id/upsTextView"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@id/titleTextView"
app:layout_constraintVertical_chainStyle="packed" />
...
通过毕加索,我通过 url 加载图像。如果原始尺寸超过 600 像素,我会裁剪图像的高度。
Picasso.with(context)
.load(url)
.resize(0, 600)
.onlyScaleDown()
.into(previewImageView)
因此,加载的图像可以是任意大小的高度和宽度,但高度不超过 600 像素。如果图像的原始大小未知,如何用占位符替换图像?
问题是多个图像位于recyclerView中,如果正在加载的图像的宽度或高度小于占位符的宽度或高度,则ViewHolder本身的大小会发生变化,如果用户位于列表中间,则从图像上方加载后,它会向上或向下抛出几个像素,这不是很顺眼。
我看到两个选项:
我不考虑允许上下缩进的选项,因为 这看起来很丑