首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >Android -无法设置背景图像,但在设计器中可见

Android -无法设置背景图像,但在设计器中可见
EN

Stack Overflow用户
提问于 2012-12-24 02:21:32
回答 3查看 1.3K关注 0票数 0

从今天起,我还算是一个Android新手。

我已经尝试将一张图片设置为背景,如下所示;

代码语言:javascript
复制
<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问题‘

当我进入设计器时,它显示了我想要的背景,但却出现了一个错误。

这样设置背景是不允许的吗?还是我错过了什么?

EN

Stack Overflow用户

发布于 2012-12-24 02:26:02

要让它工作,您需要复制您的图像在<Your_Project>/res/drawable文件夹,然后设置RelativeLayout背景为:

代码语言:javascript
复制
<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

票数 1
EN
查看全部 3 条回答
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/14013473

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档