简体   繁体   English

在Android Studio的布局预览中未显示图像

[英]image isnt showing on layout preview in android studio

Am new to app development , however I have seen multiple sources online that show you how to add an image to your layout 这是应用开发的新手,但是我在线上看到了多个资源,向您展示如何在布局中添加图像

However the image isnt being shown on the layout preview 但是,图像未显示在布局预览中

My code is below 我的代码如下

 <ImageView
    android:id="@+id/imageView"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:adjustViewBounds="true"
    android:scaleType="fitStart"
    app:srcCompat="@drawable/mm"
    tools:layout_editor_absoluteX="132dp"
    tools:layout_editor_absoluteY="16dp" />

I just don't know what I'm doing wrong .. I've followed multiple guides but still nothing 我只是不知道自己在做什么错..我遵循了多个指南,但仍然没有

Image screenshot of studio showing issue : https://imgwiz.com/image/gzHD 工作室显​​示问题的图像截图: https : //imgwiz.com/image/gzHD

My PC seems to be having issues freezing occasionally whe Android studio is running so am setting up a VPS with studio on it and will test all these suggestions on the new installation as that may be related to my issue 我的PC似乎偶尔会冻结,因为Android Studio正在运行,所以我设置了带有Studio的VPS,并将在新安装中测试所有这些建议,因为这可能与我的问题有关

Use 采用

<android.support.v7.widget.AppCompatImageView
    android:id="@+id/imageView"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:adjustViewBounds="true"
    android:scaleType="fitStart"
    app:srcCompat="@drawable/mm"
    tools:layout_editor_absoluteX="132dp"
    tools:layout_editor_absoluteY="16dp" />

instead of 代替

<ImageView
    android:id="@+id/imageView"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:adjustViewBounds="true"
    android:scaleType="fitStart"
    app:srcCompat="@drawable/mm"
    tools:layout_editor_absoluteX="132dp"
    tools:layout_editor_absoluteY="16dp" />

helped me. 帮助过我。 You can replace it without any changes in your code. 您可以替换它而无需更改代码。

In addition: Be aware of using 另外:注意使用

tools:layout_editor_absoluteX="132dp"
tools:layout_editor_absoluteY="16dp"

The namespace tools: means that it only affects your editor preview. 命名空间tools:意味着它只会影响您的编辑器预览。 As i saw in your screenshot, you are using a ConstraintLayout as parent layout. 正如我在您的屏幕截图中所看到的,您使用的是ConstraintLayout作为父级布局。 Consider adding app:layout_constraintBottom_toBottomOf etc to align your ImageView . 考虑添加app:layout_constraintBottom_toBottomOf等以对齐您的ImageView

it seems that your ImageView's position is not in the viewing area of the Design/BluePrint 您的ImageView的位置似乎不在Design / BluePrint的查看区域中

so I recommend to switch to Text mode and add these to your ImageView 所以我建议切换到“文本”模式并将其添加到您的ImageView中

tools:layout_editor_absoluteX="0dp"
tools:layout_editor_absoluteY="0dp" 

to make it show on the designer when move it to your desired position 在将其移动到所需位置时使其显示在设计器上

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM