splash.xml中的启动背景未显示在Activity SplashScreen.java中

时间:2011-11-30 08:01:15

标签: android

当我的应用加载图片数据时,我试图显示启动/欢迎屏幕,数据加载正常但是splash.xml中的背景图片不会显示,我在下面发布我的代码。

public class Splash extends Activity {

 private ChannelDB mDB;

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.splash);  
    AppConnect.getInstance(this);

    Thread splashThread = new Thread() {
        @Override
        public void run() {
           try {
               if (tabIsExist(null)==true){
                mDB.Reset();

                   Bitmap bigbang1 = BitmapFactory.decodeResource(getResources(), R.drawable.bigbang1);
                   Bitmap bigbang2 = BitmapFactory.decodeResource(getResources(), R.drawable.bigbang2);
                   Bitmap bigbang3 = BitmapFactory.decodeResource(getResources(), R.drawable.bigbang3);
                   Bitmap bigbang4 = BitmapFactory.decodeResource(getResources(), R.drawable.bigbang4);


                   mDB.createchannelEntry(new ChannelPoster(bigbang1, "生活大爆炸(第一季)" ,"http://appkon.com/hdtvs/channel/bigbang1.xml"  ,"http://movie.douban.com/subject/5372374/" ));
                   mDB.createchannelEntry(new ChannelPoster(bigbang2, "生活大爆炸(第二季)" ,"http://appkon.com/hdtvs/channel/bigbang2.xml"  ,"http://movie.douban.com/subject/3190880/" ));
                   mDB.createchannelEntry(new ChannelPoster(bigbang3, "生活大爆炸(第三季)" ,"http://appkon.com/hdtvs/channel/bigbang3.xml"  ,"http://movie.douban.com/subject/3990470/" ));
                   mDB.createchannelEntry(new ChannelPoster(bigbang4, "生活大爆炸(第四季)" ,"http://appkon.com/hdtvs/channel/bigbang4.xml"  ,"http://movie.douban.com/subject/4804079/" ));

                   }
               }catch (Exception e) {


                       Intent i = new Intent();
                       i.setClassName("com.appkon.hdtvs",
                                      "com.appkon.hdtvs.HDtvs");
                       finish();
                       startActivity(i);
                   }
                finally {

                    Intent i = new Intent();
                    i.setClassName("com.appkon.hdtvs",
                            "com.appkon.hdtvs.HDtvs");
                    finish();
                    startActivity(i);
                }

           }

     };
     splashThread.start();
}

    public boolean tabIsExist(String channelS_TABLE){
        boolean result = false;
        if(channelS_TABLE == null){
                return false;
        }
        Cursor cursor= ChannelDB.check();
        startManagingCursor(cursor);
        try {
                if(cursor.moveToNext()){
                        int count = cursor.getInt(0);
                        if(count>0){
                                result = true;
                        }
                }

        } catch (Exception e) {
            Log.e(this.toString(),"error:"+e.toString());
            Intent intent = new Intent(this,HDtvs.class);  
            startActivity(intent);  
            this.finish(); 
        }                
        return result;
    }


}

这是我的splash.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/splash">

</LinearLayout>

2 个答案:

答案 0 :(得分:1)

查看制作启动画面的更好方法simpleadvanced

答案 1 :(得分:0)

首先发布xD希望这会有所帮助。

您需要编辑AndroidManifest.xml以包含您的启动活动

    <activity android:name=".Splash"
              android:label="@string/app_name">
        <intent-filter>
            <action android:name="android.intent.action.MAIN" />
            <category android:name="android.intent.category.LAUNCHER" />
        </intent-filter>
    </activity>

请务必将类别设置为LAUNCHER,您的主要活动应如下所示

    <activity android:name=".Main"
              android:label="@string/app_name">
        <intent-filter>
            <action android:name="com.anibalismo.sovica.MAIN" />
            <category android:name="android.intent.category.DEFAULT" />
        </intent-filter>
    </activity>

不要忘记将主要类别更改为DEFAULT,并将主要操作名称更改为"com.anibalismo.sovica.MAIN" ...您认为应该使用您的包名称,但不是强制性的。

来源:Youtube: thenewboston