Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/xml/14.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Android 安卓:背景don';除了概述,我不工作_Android_Xml_Background - Fatal编程技术网

Android 安卓:背景don';除了概述,我不工作

Android 安卓:背景don';除了概述,我不工作,android,xml,background,Android,Xml,Background,我在一个Android应用程序上工作,我只是尝试在一个空的活动上放置一个背景,作为对应用程序的欢迎。在xml文件的概述中,会显示图像,但当我在emulator或手机上尝试应用程序时,不会显示图像。他们没有错,我不明白。有人能帮我吗 public class MainActivity extends Activity { private SQLiteDatabase db; @Override protected void onCreate(Bundle savedInstanceState)

我在一个Android应用程序上工作,我只是尝试在一个空的活动上放置一个背景,作为对应用程序的欢迎。在xml文件的概述中,会显示图像,但当我在emulator或手机上尝试应用程序时,不会显示图像。他们没有错,我不明白。有人能帮我吗

public class MainActivity extends Activity {

private SQLiteDatabase db;
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);

    Intent i = new Intent(this, ListeContact.class);
    try
    {
        Thread.sleep(3000);
    }
    catch (InterruptedException e)
    {
        e.printStackTrace();
    }
    startActivity(i);
    this.finish();
}
}
activity_main.xml:

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


另外,我的名为fond.png的图像位于名为drawable hdpi、drawable ldpi、drawable mdpi、drawable xdpi和drawable xxdpi的5个文件夹中。

即使将图像放置在名为just
drawable
的文件夹中,也可以解决您的问题。

不要在UI线程中调用Thread.sleep(在您的情况下,使用onCreate方法)。这可能就是原因。使用AsyncTask或alternate。

这就是我为实现您现在需要的目标所做的:

import android.os.Bundle;
import android.view.MotionEvent;
import android.app.Activity;
import android.content.Intent;
import android.content.pm.ActivityInfo;

public class SplashScreen extends Activity {

    protected int _splashTime = 5000;
    private Thread splashTread;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_splash_screen);

        this.setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);

        splashTread = new Thread() {
            @Override
            public void run() {
                try {
                    sleep(5000);
                } catch (InterruptedException e) {
                    e.printStackTrace();
                } finally {
                    startActivity(new Intent(SplashScreen.this,
                            Home.class));
                    finish();
                }
            }
        };
        splashTread.start();
    }

    @Override
    public boolean onTouchEvent(MotionEvent event)
    {
        if (event.getAction() == MotionEvent.ACTION_DOWN)
        {
            synchronized(splashTread)
            {
                    splashTread.notifyAll();
            }
        }
        return true;
    }
}
这是我的活动\u splash\u screen.xml:

<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/splash"
    tools:context=".SplashScreen" >

</RelativeLayout>

我认为问题在于调用Thread.Sleep的方式。 请尝试以下代码以获得启动屏幕:

Handler handler = new Handler();
    handler.postDelayed(new Runnable() {
        @Override
        public void run() {
                startActivity(new Intent(getApplicationContext(),
                        ListeContact.class));
            finish();

        }
    }, 3000);

我使用了您的代码并验证了..

尝试在线性布局中添加视图。您是否可以尝试注释掉线条起始触觉(I);然后看看图像是否可以显示?你没有为此设置splash活动吗?当我评论这行时,它是有效的,但我使用下面的解决方案谁工作得很好。这很好,非常感谢你的帮助。我将探索Handler以了解它是如何工作的!再次感谢
final Handler handler = new Handler();
handler.postDelayed(new Runnable() 
{
  public void run() 
   {
     Intent intent= new Intent(MainActivity.this, ListeContact.class);
     startActivity(intent);
     finish();
   }
}, 3000);