0

私は Android アプリケーションに取り組んでおり、アプリケーションでウェルカムとして空のアクティビティに背景を配置しようとしています。xmlファイルのオーバービューでは画像は表示されるのですが、エミュレーターやスマホでアプリを試してみると彼女が表示されません。エラーはありません。わかりません。誰か助けてくれませんか?

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>

PS font.png という名前の私の画像は、drawable-hdpi、drawable-ldpi、drawable-mdpi、drawable-xdpi、drawable-xxdpi という名前の 5 つのフォルダーにあります。

4

5 に答える 5

1
final Handler handler = new Handler();
handler.postDelayed(new Runnable() 
{
  public void run() 
   {
     Intent intent= new Intent(MainActivity.this, ListeContact.class);
     startActivity(intent);
     finish();
   }
}, 3000);

私はあなたのコードを使用して確認しました..

于 2013-04-30T09:38:37.937 に答える
0

drawable 問題を解決する可能性があるという名前のフォルダーにも画像を配置します

于 2013-04-30T09:11:46.840 に答える
0

UI スレッドで Thread.sleep を呼び出さないでください (この場合は onCreate メソッド)。それが原因かもしれません。AsyncTask または代替を使用します。

于 2013-04-30T09:21:25.610 に答える
0

これは、あなたが今必要としているものを達成するために私がしたことです:

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;
    }
}

これは私の activity_splash_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>
于 2013-04-30T09:23:41.750 に答える