首页 > 解决方案 > 如何使用滑动调整占位符可绘制图像的大小?

问题描述

我从 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 的中心

在此处输入图像描述

标签: androidgridviewandroid-glide

解决方案


在 Glide 4.x 版本中,您可以通过 apply() 添加 RequestOptions

 Glide
            .with(context)
            .load(path)
            .apply(new RequestOptions().override(600, 200))
            .into(imageViewResizeCenterCrop);

推荐阅读