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

时间:2018-07-10 15:23:03

标签: android android-studio android-constraintlayout

应用开发的新手,但是我在线上看到了多个来源,向您展示了如何在布局中添加图片

但是图像没有显示在布局预览中

我的代码在下面

 <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" />

我只是不知道自己在做什么错..我遵循了多个指南,但仍然没有实现

显示问题的Studio图片截图: https://imgwiz.com/image/gzHD

我的PC似乎偶尔会冻结,因为Android Studio正在运行,因此我在其上安装了Studio的VPS并会在新安装中测试所有这些建议,因为这可能与我的问题有关

2 个答案:

答案 0 :(得分:0)

使用

<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" />

代替

<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" />

帮助了我。 您可以直接替换它,而无需更改代码。

此外:请注意使用

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

名称空间tools:意味着它仅影响编辑器预览。正如我在您的屏幕快照中看到的那样,您使用的是ConstraintLayout作为父级布局。考虑添加app:layout_constraintBottom_toBottomOf等来对齐您的ImageView

答案 1 :(得分:0)

您的ImageView的位置似乎不在Design / BluePrint的查看区域中

所以我建议切换到文本模式 并将它们添加到您的ImageView

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

将其移动到所需位置时在设计器上显示

相关问题