【发布时间】:2016-04-21 19:51:12
【问题描述】:
我无法添加图片。我下载了图像并将其添加到 drawable-mdpi 下的 res 目录中。然后当我尝试使用 imageView 在视图上添加图像时,它给了我这个错误
Couldn't resolve resource @drawable/ball01
Failed to convert @drawable/ball01 into a drawable
这是我的 xml
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/container"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".MainActivity"
tools:ignore="MergeRootFrame" >
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/textView"
android:layout_gravity="center"
android:textSize="32sp"
android:layout_above="@+id/button"
android:layout_centerHorizontal="true" />
<Button
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Enlighten Me"
android:id="@+id/button"
android:layout_centerVertical="true"
android:layout_alignParentRight="true" />
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/imageView"
android:layout_above="@+id/textView"
android:layout_centerHorizontal="true"
android:src="@drawable/ball01" />
</RelativeLayout>
我在这里做错了什么。
【问题讨论】:
-
检查图像文件名并确保它与您在
@drawable\...中指定的名称匹配或检查图像的扩展名并确保它是jpg,png,jpeg... -
这听起来很傻,但是您是否尝试在将图像添加到您的可绘制文件夹后刷新您的项目文件夹?
-
这就是尼拉吉。我不得不关闭 IDE 并返回...谢谢