Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/xml/13.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Android “中的图像预览”;“设计模式”;在尚未以编程方式设置的视图上_Android_Xml_Button_Imageview - Fatal编程技术网

Android “中的图像预览”;“设计模式”;在尚未以编程方式设置的视图上

Android “中的图像预览”;“设计模式”;在尚未以编程方式设置的视图上,android,xml,button,imageview,Android,Xml,Button,Imageview,我想知道是否有一个xml标记,它允许我在ImageViews和/或按钮s的设计模式下查看图像的预览(因此无需实际使用app:srcCompat或android:background) 这是因为我将在java文件中以编程方式设置真实图像 举个例子,我指的是类似tool:text的TextView: <TextView android:id="@+id/text_view" android:layout_width="match_parent" android:layo

我想知道是否有一个xml标记,它允许我在
ImageView
s和/或
按钮
s的设计模式下查看图像的预览(因此无需实际使用
app:srcCompat
android:background

这是因为我将在java文件中以编程方式设置真实图像

举个例子,我指的是类似
tool:text
TextView

<TextView
    android:id="@+id/text_view"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    tool:text="Here will be displayed some text" />

您可以使用
工具
命名空间anywhere
在预览模式下应用xml属性值

下面是一个例子:

<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:src="@drawable/common_google_signin_btn_text_dark_pressed"/>

</LinearLayout>


您可以在预览模式下查看图像。

谢谢您的回答!我刚刚将
tools:src=“@drawable/my_icon”
添加到
ImageView
xmlns:tools=”http://schemas.android.com/tools“
到根
LinearLayout
但它不工作:(它不会给出任何错误,尽管您的视图可能在布局外部绘制?您可以共享布局文件吗?”?