ImageView 未显示在 phone 中,但显示在 Android Studio 中

ImageView not showing in phone but showing in Android Studio

我的问题是,当我使用“选择资源”工具添加 ImageView 时,图像显示在 Android Studio 中 activity 的布局中。但是当我在 phone 上执行它时,它是 Huawei Y7 Prime。根本不显示。

我逐步尝试了其他问题中提出的许多解决方案,但似乎没有任何一个有效。

  1. 尝试使用 android.support.v7.widget.AppCompatImageView 而不是 ImageView,但 android 工作室似乎无法识别它。我在 中设置了所有步骤...但是 -> 不工作!
  2. 我使用了 android:src 而不是 app:srcCompat,就像 中所说的 -> 不工作!
  3. 我在 AndroidManifest.xml 文件中的应用程序标签中设置了这样一行代码 android:hardwareAccelerated="false" -> 也不起作用!
  4. 使用 src 而不是像
  5. 那样的 srcCompat

我使用了非常基本的代码来设置 ImageView

<ImageView
        android:id="@+id/imageView3"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        tools:srcCompat="@tools:sample/backgrounds/scenic" />

我使用 LayoutInspector 工具查看图像是否显示。我发现不是。

请问有人能帮忙吗??

而不是使用 tools:srcCompat,你应该使用 android:src

tools 命名空间用于调试目的,这就是它在 AndroidStudio 中可见但在实际设备中不可见的原因。

此外,请确保您的来源使用有效参考(或来自 android 的参考)。例如:

android:src="@drawable/your_image"