【问题标题】:ImageView not showing in phone but showing in Android StudioImageView 未在手机中显示但在 Android Studio 中显示
【发布时间】:2020-06-30 05:11:38
【问题描述】:

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

我逐步尝试了其他问题中提出的许多解决方案,但其中任何一个似乎都不起作用。

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

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

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

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

请问有人可以帮忙吗?

【问题讨论】:

    标签: java android imageview


    【解决方案1】:

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

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

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

    android:src="@drawable/your_image"
    

    【讨论】:

    • 试过了..但它说:无法解析@tools:sample/backgrounds/scenic的符号!
    • 就像我说的,使用实际的图像参考。不要使用tools 命名空间。
    • 谢谢你的帮助@waqaslam 我明白了。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-08-28
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多