Vector drawable does not work as placeholder image on API 17 (and probably below API 21)
See original GitHub issueDescription
I have a SimpleDraweeView
and a vector drawable XML. I tried to use the said XML as a placeholder in the Drawee but on API 17 (so probably below API 21) could not inflate the view and crashed the app.
AppCompatDelegate.setCompatVectorFromResourcesEnabled(true)
does not seem to be a viable option as
This feature defaults to disabled, since enabling it can cause issues with memory usage, and problems updating Configuration instances.
Reproduction
Define the layout XML for the Drawee:
<com.facebook.drawee.view.SimpleDraweeView
android:id="@+id/cover"
android:layout_width="60dp"
android:layout_height="87dp"
android:layout_marginEnd="12dp"
android:layout_marginRight="12dp"
app:imageUri="@{item.cover}"
fresco:actualImageScaleType="centerCrop"
fresco:placeholderImage="@drawable/ic_image_white_24dp"
fresco:placeholderImageScaleType="centerInside"/>
where @drawable/ic_image_white_24dp
is ic_image_white_24dp.xml
:
<vector xmlns:android="http://schemas.android.com/apk/res/android"
android:width="24dp"
android:height="24dp"
android:viewportWidth="24.0"
android:viewportHeight="24.0">
<path
android:fillColor="#FFFFFFFF"
android:pathData="M21,19V5c0,-1.1 -0.9,-2 -2,-2H5c-1.1,0 -2,0.9 -2,2v14c0,1.1 0.9,2 2,2h14c1.1,0 2,-0.9 2,-2zM8.5,13.5l2.5,3.01L14.5,12l4.5,6H5l3.5,-4.5z"/>
</vector>
Note that the SimpleDraweeView
has an app:imageUri
attribute this is here because the data binding would not work otherwise, the implementation is pretty simple (it is not relevant to the bug though):
@BindingAdapter({"imageUri"})
public static void loadImage(SimpleDraweeView view, Uri imageUrl) {
view.setImageURI(imageUrl);
}
The layout gets inflated by DataBindingUtil
from a RecyclerView.Adapter
located in a (support) Fragment
that is attached to the parent AppCompatActivity
.
The gradle file contains the necessary line for supporting vector drawables on lower API levels:
android {
defaultConfig {
vectorDrawables.useSupportLibrary = true
}
}
Additional Information
- Fresco version: 1.3.0
- Platform version: API 17, HTC One X
- Support lib version: 25.3.1
Issue Analytics
- State:
- Created 6 years ago
- Comments:11 (2 by maintainers)
Top GitHub Comments
@oprisnik I was able to fix this issue by adding
AppCompatDelegate.setCompatVectorFromResourcesEnabled(true);
in the onCreate of Application class. and this automatically fixesfresco:placeholderImage="@drawable/vector_graphic"
I have tested this in API level 19.
A similar question is posted on stackoverflow
This should also be added on official documentation FAQ’s section.
@ibtisamasif The problem with that call is clearly documented: