Android中是否有用于ImageView内容的工具属性? [英] Is there a tools attribute for ImageView content in Android?
问题描述
我找不到用于在Android版式中设置示例图片的 tools 属性.我的假设是,目前没有这种东西,至少没有直接支持.
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.
您如何在设计时使用 tools 在Android中定义图像占位符?
How do you define image placeholders at design time in Android with tools?
TextView的 tools 属性示例(即文本的 tools:text 属性):
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"/>
推荐答案
就像TextView
一样简单.只需使用tools:src
设置图像即可.
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" />
这篇关于Android中是否有用于ImageView内容的工具属性?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!