Hi, I'm trying to use a vector drawable as a place...
# compose
r
Hi, I'm trying to use a vector drawable as a placeholder image while the actual one is loading (I'm using Glide for this). When I try to use the following vector (simple gray rectangle, no animation),
Copy code
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="<http://schemas.android.com/apk/res/android>"
    android:shape="rectangle">
    <solid android:color="#bfbfbf" />
</shape>
in an
Image
composable like this,
Copy code
Image(asset = vectorResource(id = R.drawable.img_placeholder))
I get
Copy code
Binary XML file line #3<VectorGraphic> tag requires viewportWidth > 0
I tried: • setting
modifier = Modifier.fillMaxWidth()
on the
Image
composable and on a wrapper
Column
as well • adding
<size android:width="10dp" android:height="10dp" />
in the drawable's xml But this didn't help. Without composables, I was using the above-mentioned drawable as a placeholder parameter to Glide, like this:
Copy code
val drawable = ContextCompat.getDrawable(context, R.drawable.img_placeholder)!! as GradientDrawable
...
Glide.with(context)
        .load(imageUrl)
        .placeholder(drawable)
Is it necessary to use
<vector>
? (
<shape>
can't be direct child of it) Or maybe I need to create proramatically a bitmap (in this case it's simple enough to do so, but it's just an example)? Note that other vector drawables, based on
<vector>
work fine (probably because they have
viewportWidth
and
viewportHeight
attrs set).
Thank you!