I could not find a tools attribute to set an example image in a layout for Android. My assumption is that there is no such thing at the moment, at least no direct support.
But I was wondering whether I just did not search well enough or whether there is a workaround for this.
How do you define image placeholders at design time in Android with tools?
Example of a tools attribute for a TextView (i.e. the tools:text attribute for text):
<TextView
android:id="@+id/tv_vote_average"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textSize="16sp"
android:textStyle="bold"
tools:text="8.4/10"/>
It's just straightforward like for the TextView
. Just use tools:src
to set the image.
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
tools:src="@drawable/placeholder" />
Use this for random real sample images:
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:scaleType="centerCrop"
tools:src="@tools:sample/backgrounds/scenic" />
tools:background works for me too.
<?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:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent">
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
tools:background="@mipmap/ic_launcher"/>
</LinearLayout>