无法将图像作为Android活动背景

时间:2015-01-06 17:08:35

标签: android xml android-activity background

我试图将图片作为背景,但我不明白为什么它不起作用。

这是我的activity_start.xml

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:background="@drawable/startbackg" >

    <TextView
        android:id="@+id/textView1"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentBottom="true"
        android:layout_centerHorizontal="true"
        android:layout_marginBottom="153dp"
        android:textColor="#555555"
        android:textSize="30sp"
        android:text="Hello" />

</RelativeLayout>

和StartActivity.java

import android.app.Activity;
import android.os.Bundle;

public class StartActivity extends Activity {

    /** Called when the activity is first created. */
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_start);

    }

}

在eclipse中,我可以正确地看到背景,如下所示:

eclipse preview

但是当我在nexus 7中运行它时,我看不到任何背景图像

app in phone

我不知道该尝试什么......有什么想法吗?

这是我使用

的图像

enter image description here

1 个答案:

答案 0 :(得分:0)

使用

    int sdk = android.os.Build.VERSION.SDK_INT;
    if (sdk < android.os.Build.VERSION_CODES.JELLY_BEAN) {
        myLInearLayout.setBackground(myImage);
        myLInearLayout.setBackgroundDrawable(myImage);

    } else {

        myLInearLayout.setBackground(myImage);

    }