【问题标题】:android.view.InflateException when use an imageviewandroid.view.InflateException 使用 imageview 时
【发布时间】:2017-09-27 11:06:54
【问题描述】:

我试图将图像视图放在顶部以显示徽标,但是当我运行应用程序时出现此错误:

android.view.InflateException:二进制 XML 文件第 13 行:错误 膨胀类 android.widget.ImageView

如果我删除该图像视图,代码运行没有问题

我如何解决这个问题是 activity_main.xml

<?xml version="1.0" encoding="utf-8"?>
    <RelativeLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:paddingTop="@dimen/activity_vertical_margin"
    android:background="#2e3138"

    tools:context="dattasolutions.cloud.dattasolutionscloud.MainActivity"
    android:orientation="vertical"
  >
    <ImageView
        android:layout_width="wrap_content"
        android:layout_height="60dp"
        android:src="@drawable/logo"
        android:id="@+id/imageView"
        />

    <TextView

        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:gravity="center"
        android:textSize="17sp"
        android:id="@+id/tvHeading"
        android:text="Presiona el icono para subir archivos al servidor"
        android:textColor="#fff"
        android:textStyle="bold"
        android:layout_marginTop="64dp" />
    <ImageView
        android:id="@+id/ivAttachment"
        android:layout_width="100dp"
        android:layout_height="100dp"
        android:src="@drawable/attach_icon"
        android:layout_centerVertical="true"
        android:layout_centerHorizontal="true"
        android:layout_x="145dp"
        android:layout_y="171dp" />

    <TextView
        android:id="@+id/tv_file_name"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:textColor="#fff"
        android:layout_marginTop="10dp"
        android:gravity="center"
        android:layout_below="@+id/ivAttachment"
        android:layout_centerHorizontal="true"/>

    <Button
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:id="@+id/b_upload"
        android:text="Upload"
        android:textStyle="bold"
        android:textSize="20sp"
        android:layout_alignParentBottom="true"
        android:gravity="center"
        android:textColor="#fff"
        android:background="#039be5"/>



</RelativeLayout>

【问题讨论】:

  • 你的图片是矢量图标还是 png?
  • 在 logcat 中往下看。您应该看到另一个指向真正问题的错误。如果您不明白发生了什么,请在此处发布该错误。
  • png 图片和它只有 400kb

标签: android layout imageview inflate-exception


【解决方案1】:

尝试替换。 android:src="@drawable/logo"

与。
app:srcCompat="@drawable/logo"
reason

如果仍然无法正常工作,请检查图像的大小。有时它实际上不是通货膨胀问题,而是更深层次的问题,即导致通货膨胀异常的内存问题。使用最小必要尺寸的图像。 希望对您有所帮助。

【讨论】:

  • app:srcCompat="@drawable/logo" 会导致错误,但 android:srcCompat="@drawable/logo" 不会,除了它不显示图像
  • 尝试使用较小尺寸的不同图像进行测试。
  • 图片大小接近400kb
  • 日志中有什么相关的吗?你试过不同的图片吗?
【解决方案2】:

可能是你的图片名为“logo”的问题试试其他图片,看看是不是图片格式或大小等问题。这样你将轻松了解问题以及您在未来应该使用哪种类型的图像。祝你好运!

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-03-04
    • 2012-10-04
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多