【问题标题】:ImageView src not showing in xmlImageView src 未在 xml 中显示
【发布时间】:2018-12-17 08:30:52
【问题描述】:

我已在可绘制对象中粘贴了一个图像文件,但它没有显示在 XML 文件中。

在下面的代码中,“src”之后的部分得到红色高亮显示,即使我在 Drawable 中有相同的命名文件。

这是 XML 代码:

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    tools:context=".Splash">

    <ImageView
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:id="@+id/splashImage" 
        android:src="@drawable/splash"

【问题讨论】:

  • ImageView 上没有 src 属性。
  • 将此添加到图像视图 android:src="@drawable/ic_launcher" 并查看

标签: android xml image imageview


【解决方案1】:
<LinearLayout
 xmlns:android="http://schemas.android.com/apk/res/android"
 android:layout_width="match_parent"
 android:layout_height="match_parent">
 <ImageView
     android:layout_width="wrap_content"
     android:layout_height="wrap_content"
     **android:src="@mipmap/ic_launcher"**
     />

【讨论】:

    【解决方案2】:

    1- 确保您的 XML 文件格式正确

    2- 确保您的图片名称没有特殊字符,然后清理您的项目

    如果这不起作用

    尝试使缓存无效并重新启动(文件 -> 使缓存无效和 /Restart)

    【讨论】:

      【解决方案3】:

      你可以试试这个:

      • 清理并重建项目
      • 关闭并重新打开 AndroidStudio
      • 检查图像文件的格式是否正确或能够读取

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 2012-12-12
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2015-11-09
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多