从今天起,我还算是一个Android新手。
我已经尝试将一张图片设置为背景,如下所示;
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:background="C:\Users\Jacob\Downloads\xmas.jpg"
android:layout_height="match_parent"
tools:context=".MainActivity" >但是当我构建它的时候,我想出了;
‘说明资源路径位置类型错误:错误:不允许字符串类型(位于值为’C:\Users\Jacob\Downloads\xmas.jpg‘的'background’)。activity_main.xml /FirstAndroidApp/res/布局第1行Android AAPT问题‘
当我进入设计器时,它显示了我想要的背景,但却出现了一个错误。
这样设置背景是不允许的吗?还是我错过了什么?
发布于 2012-12-24 02:26:02
要让它工作,您需要复制您的图像在<Your_Project>/res/drawable文件夹,然后设置RelativeLayout背景为:
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:background="@drawable/xmas"
android:layout_height="match_parent"
tools:context=".MainActivity" >有关在项目中添加图像的更多信息,请参见
http://developer.android.com/guide/topics/resources/drawable-resource.html
https://stackoverflow.com/questions/14013473
复制相似问题