Hi,
Is it possible to reduce only placeholder size. The placeholder image takes the size of actual image size that has been given. I would to show smaller size placeholder.
Glide.with(mContext.getApplicationContext())
.load(tempURL)
.diskCacheStrategy(DiskCacheStrategy.SOURCE)
.placeholder(R.mipmap.ic_launcher)
.into(personViewHolder.image);
My ImageView in xml
<com.ylg.myapp.SquareImageView
android:id="@+id/grid_item_image"
android:layout_width="150dp"
android:layout_height="150dp"
android:background="@android:color/transparent"
android:paddingLeft="5dp"
android:paddingRight="5dp"
android:focusable="false" />
Is this possible?
One way is to create a wrapping drawable: your ic_launcher is 48x48dp, you want to put it inside 150dp so you need the add spaces around your original drawable: (150-48)/2 = 51:
<?xml version="1.0" encoding="utf-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
<item><shape><stroke android:color="#000000" android:width="1dp" /></shape></item>
<item android:drawable="@drawable/ic_launcher"
android:left="51dp" android:right="51dp" android:top="51dp" android:bottom="51dp" />
</layer-list>
Remove the <item with the stroke inside, I put it there so you can see the edges in the preview in the IDE. Use this as your placeholder, you can put it in drawable-nodpi.
Great. Thanks. This worked.
For future readers, based on TWiStErRob's comment here's the xml layout that I ended up to:
<?xml version="1.0" encoding="utf-8"?>
<inset xmlns:android="http://schemas.android.com/apk/res/android"
android:inset="10dp">
<layer-list>
<item android:drawable="@drawable/my_drawable" />
</layer-list>
</inset>
This will apply 10dp padding on all sides (left, top, right, bottom) to my_drawable.
One way is to create a wrapping drawable: your
ic_launcheris 48x48dp, you want to put it inside 150dp so you need the add spaces around your original drawable:(150-48)/2 = 51:<?xml version="1.0" encoding="utf-8"?> <layer-list xmlns:android="http://schemas.android.com/apk/res/android"> <item><shape><stroke android:color="#000000" android:width="1dp" /></shape></item> <item android:drawable="@drawable/ic_launcher" android:left="51dp" android:right="51dp" android:top="51dp" android:bottom="51dp" /> </layer-list>Remove the
<itemwith the stroke inside, I put it there so you can see the edges in the preview in the IDE. Use this as your placeholder, you can put it indrawable-nodpi.
This answer doesn't work on API 19 Version
<?xml version="1.0" encoding="utf-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
<!-- needs the extra spacing otherwise the drawable will be too big -->
<item android:drawable="@drawable/ic_black_photo"
android:left="51dp" android:right="51dp" android:top="51dp" android:bottom="51dp" />
</layer-list>
Glide.with(context)
.load(itemList.get(i).getLink())
.apply(RequestOptions.fitCenterTransform())
.placeholder(R.drawable.glide_black_photo_placeholder)
.into(holder.imageView);
I am getting error:
android.content.res.Resources$NotFoundException: File res/drawable/glide_black_photo_placeholder.xml from drawable resource ID #0x7f080098. If the resource you are trying to use is a vector resource, you may be referencing it in an unsupported way. See AppCompatDelegate.setCompatVectorFromResourcesEnabled() for more info.
even with this enabled:
static {
if (android.os.Build.VERSION.SDK_INT <= Build.VERSION_CODES.KITKAT){
AppCompatDelegate.setCompatVectorFromResourcesEnabled(true);
}
}
has anyone found a workaround solution?
Most helpful comment
One way is to create a wrapping drawable: your
ic_launcheris 48x48dp, you want to put it inside 150dp so you need the add spaces around your original drawable:(150-48)/2 = 51:Remove the
<itemwith the stroke inside, I put it there so you can see the edges in the preview in the IDE. Use this as your placeholder, you can put it indrawable-nodpi.