我的应用程序没有显示在应用程序抽屉上

时间:2014-01-21 08:35:34

标签: java android xml

Heyy伙计们..我正在做一个简单的应用程序,带有启动画面和帧动画,用于在启动画面上显示gif ......事情是......应用程序已安装但未显示在应用程序上抽屉 这是显而易见的。 基本上它是我想先运行的Splash活动,然后是主要活动。

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="com.example.placebo"
    android:versionCode="1"
    android:versionName="1.0" >

    <uses-sdk
        android:minSdkVersion="10"
        android:targetSdkVersion="14" />
    <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"/>

    <application
        android:allowBackup="true"
        android:icon="@drawable/ic_launcher"
        android:label="@string/app_name"
        android:theme="@style/AppTheme" >
        <activity
            android:name="com.example.placebo.Main"
            android:label="@string/app_name" >

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

                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
            </activity>
        <activity 
            android:name=".WifiState"
            ></activity>
        <activity 
            android:name=".ColorPlay"
            ></activity>
    </application>

</manifest>

继承人飞溅

package com.example.placebo;

import android.app.Activity;
import android.content.Intent;
import android.graphics.drawable.AnimationDrawable;
import android.os.Bundle;
import android.widget.ImageView;

public class Splash extends Activity {
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        // TODO Auto-generated method stub
        super.onCreate(savedInstanceState);
        setContentView(R.layout.splash);
        ImageView iv = (ImageView) findViewById(R.id.iv1);
        iv.setBackgroundResource(R.animator.animation);
        AnimationDrawable anim = (AnimationDrawable) iv.getBackground();
        anim.start();
        startActivity(new Intent(Splash.this,Main.class));
    }
}

继承动画片xml

<?xml version="1.0" encoding="utf-8"?>
<animation-list xmlns:android="http://schemas.android.com/apk/res/android" >
    <item android:drawable="@drawable/frame_000" android:duration="40"/>
    <item android:drawable="@drawable/frame_001" android:duration="40"/>
    <item android:drawable="@drawable/frame_002" android:duration="40"/>
    <item android:drawable="@drawable/frame_003" android:duration="40"/>
    <item android:drawable="@drawable/frame_004" android:duration="40"/>
    <item android:drawable="@drawable/frame_005" android:duration="40"/>
    <item android:drawable="@drawable/frame_006" android:duration="40"/>
    <item android:drawable="@drawable/frame_007" android:duration="40"/>
    <item android:drawable="@drawable/frame_008" android:duration="40"/>
    <item android:drawable="@drawable/frame_009" android:duration="40"/>
    <item android:drawable="@drawable/frame_010" android:duration="40"/>
    <item android:drawable="@drawable/frame_011" android:duration="40"/>
    <item android:drawable="@drawable/frame_012" android:duration="40"/>
    <item android:drawable="@drawable/frame_013" android:duration="40"/>
    <item android:drawable="@drawable/frame_014" android:duration="40"/>
    <item android:drawable="@drawable/frame_015" android:duration="40"/>
    <item android:drawable="@drawable/frame_016" android:duration="40"/>
    <item android:drawable="@drawable/frame_017" android:duration="40"/>
    <item android:drawable="@drawable/frame_018" android:duration="40"/>
    <item android:drawable="@drawable/frame_019" android:duration="40"/>

</animation-list>

和Main.java

package com.example.placebo;

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

    public class Main extends Activity implements OnClickListener {

        @Override
        protected void onCreate(Bundle savedInstanceState) {
            super.onCreate(savedInstanceState);
            setContentView(R.layout.main);
            Button b1= (Button) findViewById(R.id.button1);
            b1.setOnClickListener(this);
            Button b2= (Button) findViewById(R.id.button2);
            b2.setOnClickListener(this);

        }



        @Override
        public void onClick(View v) {
            if(v.getId()==R.id.button1) {
                startActivity(new Intent(Main.this, WifiState.class));
            }
            if(v.getId()==R.id.button2) {
                startActivity(new Intent(Main.this, ColorPlay.class));
            }

        }

    }

2 个答案:

答案 0 :(得分:0)

将其更改为:

protected void onCreate(Bundle savedInstanceState) {
    // TODO Auto-generated method stub
    super.onCreate(savedInstanceState);
    setContentView(R.layout.splash);
    ImageView iv = (ImageView) findViewById(R.id.iv1);
    iv.setBackgroundResource(R.animator.animation);
    AnimationDrawable anim = (AnimationDrawable) iv.getBackground();
    anim.start();
            new Handler().postDelayed(new Runnable() {

        @Override
        public void run() {
              startActivity(new Intent(Splash.this,Main.class));
        }
    }, 2000);

}

答案 1 :(得分:0)

试试这个。

private static int SPLASH_TIME_OUT = 3000;
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_splash);

    //To Delay by 3 Seconds
    new Handler().postDelayed(new Runnable() {
        @Override
        public void run() {
            // This method will be executed once the timer is over
            // Start your app main activity
            Intent i = new Intent(Splash.this, MainActivity.class);
            startActivity(i);
            // close this activity
            finish();
        }
    }, SPLASH_TIME_OUT);

    }

您可以将 drawable image 保留为 activity_splash 布局的背景。

相关问题