在android中为RelativeLayout添加背景图片

Dnw*_*hma 1 android background background-image android-layout

我尝试使用添加背景图片到Android应用程序android:background="@drawable/imageURL".我将图像添加到drawable-hdpi文件夹,但是我收到了错误.我正在尝试将图像添加到RelativeLayout.我也试过用,LinearLayout但它也没用.

那么如何RelativeLayout在Android中向我的应用添加背景图像?

错误是什么?

<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:background="@drawable/abc.png"
    android:paddingBottom="@dimen/activity_vertical_margin"
    android:paddingLeft="@dimen/activity_horizontal_margin"
    android:paddingRight="@dimen/activity_horizontal_margin"
    android:paddingTop="@dimen/activity_vertical_margin"
    tools:context=".MainActivity" >

    <TextView
      android:layout_width="wrap_content"
      android:layout_height="wrap_content"
      android:text="@string/hello_world" />

    </RelativeLayout>
Run Code Online (Sandbox Code Playgroud)

Bla*_*elt 5

更换

android:background="@drawable/abc.png"
Run Code Online (Sandbox Code Playgroud)

android:background="@drawable/abc"
Run Code Online (Sandbox Code Playgroud)

从文档:

可能是对另一个资源的引用,格式为"@ [+] [package:] type:name"

正如您所看到的,扩展名不是属性值的一部分