Fresco 1.13.0中SimpleDraweeView的tools预览属性失效问题求助
I get it, dealing with Fresco's SimpleDraweeView not recognizing Android Studio's tools attributes can be frustrating—especially when you want to preview your RecyclerView items without firing up an emulator. Let's break down why this happens and how to fix it with your 1.13.0 version of Fresco.
Why tools:placeholderImage Isn't Working
Fresco's SimpleDraweeView is a custom View, and its properties (like placeholderImage) are handled through Fresco's own namespace (usually app:), not the Android SDK's tools: namespace. Older versions of Fresco (like 1.13.0) don't support mapping tools: attributes to their own View properties, so the layout editor ignores tools:placeholderImage.
Two Workarounds for Previewing Sample Images
Here are two reliable ways to get that preview working without changing your runtime code:
1. Use tools:background for Quick Preview
You can leverage the tools:background attribute to set a sample image that only shows up in the layout editor. When your app runs, Fresco's loaded image will cover this background, so it won't affect your actual UI.
<?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent" android:layout_height="350dp" android:orientation="horizontal"> <com.facebook.drawee.view.SimpleDraweeView android:id="@+id/drawee_product_desc" android:layout_width="match_parent" android:layout_height="match_parent" tools:background="@tools:sample/avatar" /> </LinearLayout>
2. Add a Preview-Only ImageView
For a more accurate preview (especially if you need to match aspect ratios or avoid background overlap), add an ImageView that's hidden at runtime but visible in the editor. This mimics exactly how your SimpleDraweeView will look:
<?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent" android:layout_height="350dp" android:orientation="horizontal"> <com.facebook.drawee.view.SimpleDraweeView android:id="@+id/drawee_product_desc" android:layout_width="match_parent" android:layout_height="match_parent" /> <!-- Preview image only visible in layout editor --> <ImageView android:layout_width="match_parent" android:layout_height="match_parent" android:visibility="gone" <!-- Hidden at runtime --> tools:visibility="visible" <!-- Shown in editor --> tools:src="@tools:sample/avatar" /> </LinearLayout>
Bonus: Upgrade Fresco (If Possible)
If your project allows it, upgrading to a newer Fresco version (2.x or later) adds support for tools: attributes like tools:placeholderImage, so you can use your original code directly without workarounds.
内容的提问来源于stack exchange,提问作者Divya Gupta

