【问题标题】:How to resize placeholder drawable image with glide?如何使用滑动调整占位符可绘制图像的大小?
【发布时间】:2020-07-13 03:22:02
【问题描述】:

我从 git 和 stackoverflow 尝试了很多答案,但我没有找到正确的解决方案。

我在 gridview 中使用了 glide。 在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)的情况下调整占位符大小。 问题是占位符(加载条图像)也在 centercrop 目前它看起来像下图。我想要这个加载栏 30x30 dp 在 imageview 的中心

【问题讨论】:

    标签: android gridview android-glide


    【解决方案1】:

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

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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2015-10-26
      • 1970-01-01
      • 1970-01-01
      • 2019-01-22
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多