Java 为什么android xml不允许您为不同的布局使用两个以上的不同背景?

Java 为什么android xml不允许您为不同的布局使用两个以上的不同背景?,java,android,xml,android-layout,android-intent,Java,Android,Xml,Android Layout,Android Intent,我有3个活动,我想使用不同的背景。但是当我这样做的时候,我得到了这个错误,但是如果我只在两个活动中使用不同的背景,那么这个应用程序就可以工作了 在日志中:- 11-20 13:40:25.855: E/AndroidRuntime(849): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.medepad.community_virtual_ward/com.medepad.community_virt

我有3个活动,我想使用不同的背景。但是当我这样做的时候,我得到了这个错误,但是如果我只在两个活动中使用不同的背景,那么这个应用程序就可以工作了

日志中:-

11-20 13:40:25.855: E/AndroidRuntime(849): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.medepad.community_virtual_ward/com.medepad.community_virtual_ward.Temperature}: android.view.InflateException: Binary XML file line #2: Error inflating class <unknown>
温度代码

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

</LinearLayout>
欢迎使用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:orientation="vertical"
    android:background="@drawable/welcome" >

    <TextView
        android:id="@+id/textView2"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentLeft="true"
        android:layout_alignParentTop="true"
        android:layout_marginLeft="400dp"
        android:layout_marginTop="115dp"
        android:text="TextView"
        android:textColor="#000000"
        android:textSize="40dp" />

</RelativeLayout>

正如您从代码中看到的,我已将activity_main设置为有一个名为main的背景,activity welcome设置为有一个背景欢迎,最后activity temperature设置为有一个背景温度,这些都在我的可绘制文件夹中。当我运行此程序时,应用程序将启动activity_main,然后文本视图将打开下一个activity welcome。但是当我在欢迎打开温度中单击下一个文本视图时,我得到了上面的错误。但是,如果我将温度背景更改为早期的xml背景之一,如main或welcome。整个应用程序工作正常。所以让我们澄清一下,因为没有人能够解决这个问题。在我使用3种不同的背景之前,该应用程序一直有效。你自己试试看,android肯定有问题,但如果你让它工作,请将代码粘贴到这里,或者告诉我代码中的错误在哪里。那我为什么会出现这个错误呢?

问题肯定不在于使用3个背景。。。你完全可以在不同的活动中使用不同的背景。那么问题出在哪里呢?????粘贴你的@drawable/welcome、@drawable/temperature、@drawable/main文件。我怀疑@drawable/temperature是问题所在……同时使用多个问号也不会加快解决问题的速度……我想大胆猜测一下,你的背景可绘制图像可能是高分辨率图像?如果这是真的,那么在stracktrace的某个地方,你可能会找到一个。
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical"
    android:background="@drawable/temperature" >

</LinearLayout>
package com.medepad.community_virtual_ward;

import android.app.Activity;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;

public class Temperature extends Activity implements OnClickListener {


@Override
protected void onCreate(Bundle savedInstanceState) {
    // TODO Auto-generated method stub
    super.onCreate(savedInstanceState);
    setContentView(R.layout.temperature);
}

@Override
public void onClick(View v) {
    // TODO Auto-generated method stub

}
}
<?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:orientation="vertical"
    android:background="@drawable/welcome" >

    <TextView
        android:id="@+id/textView2"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentLeft="true"
        android:layout_alignParentTop="true"
        android:layout_marginLeft="400dp"
        android:layout_marginTop="115dp"
        android:text="TextView"
        android:textColor="#000000"
        android:textSize="40dp" />

</RelativeLayout>
package com.medepad.community_virtual_ward;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.TextView;

public class Welcome extends Activity implements OnClickListener {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        // TODO Auto-generated method stub
        super.onCreate(savedInstanceState);
        setContentView(R.layout.welcome);
        TextView next= (TextView)findViewById(R.id.textView2);
        next.setOnClickListener(this);
    }

    @Override
    public void onClick(View v) {
        // TODO Auto-generated method stub
        Intent temperature= new Intent(this, Temperature.class);
        startActivity(temperature);
    }
}