简体   繁体   中英

How to resize placeholder drawable image with glide?

I tried many answer from git and stackoverflow but i didn't find right solution.

I used glide in gridview. In 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>

in 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);

and my drawable is

<animated-rotate
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:drawable="@drawable/people_image_loading_spinner"
    android:pivotX="50%"
    android:pivotY="50%"
    />

i want to resize my placeholder size without changes of original image scaletype(centerCrop). problem is placehoder(loading bar image) is also in centercrop currently its look like below image. i want to this loading bar 30x30 dp in center of imageview

在此处输入图像描述

In version of Glide 4.x, you can add RequestOptions through apply()

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM