关于android中的启动屏幕

关于android中的启动屏幕,android,splash-screen,Android,Splash Screen,我有这个启动屏幕的代码。当我运行它时,它会在模拟器上显示一个错误 “应用程序animatedsplashscreen(process com.animated.splash)意外停止。请重试。” <uses-sdk android:minSdkVersion="10" /> <application android:icon="@drawable/icon" android:label="@string/app_name" > <activ

我有这个启动屏幕的代码。当我运行它时,它会在模拟器上显示一个错误 “应用程序animatedsplashscreen(process com.animated.splash)意外停止。请重试。”

<uses-sdk android:minSdkVersion="10" />

<application
    android:icon="@drawable/icon"
    android:label="@string/app_name" >
    <activity
        android:name=".AnimatedSplashScreenActivity"
        android:label="@string/app_name" >
        <intent-filter>
            <action android:name="android.intent.action.MAIN" />

            <category android:name="android.intent.category.LAUNCHER" />
        </intent-filter>
    </activity>
<activity android:name=".MainActivity"
    android:label="@string/hello">
    <intent-filter>
        <action android:name="com.animated.splash.MainActivity"/>
        <category android:name="android.intent.category.DEFAULT"/>
    </intent-filter>
</activity>    

</application>

</manifest>
我在这里附上整个代码

this is AnimatedSplashScreenActivity.java file.

package com.animated.splash;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.animation.Animation;
import android.view.animation.AnimationUtils;
import android.view.animation.LayoutAnimationController;
import android.view.animation.Animation.AnimationListener;
import android.widget.TableLayout;
import android.widget.TableRow;
import android.widget.TextView;

public class AnimatedSplashScreenActivity extends Activity {
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.main);
    startAnimating();

}
/** 
 * Helper method to start the animation on the splash screen
 */
private void startAnimating()
{
    //Fade in top title

    TextView logo1 = (TextView) findViewById(R.id.TextViewTopTitle);
    Animation fade1 = AnimationUtils.loadAnimation(this,R.anim.fade_in);
    logo1.startAnimation(fade1);
    TextView logo2=(TextView) findViewById(R.id.TextViewBottomTitle);
    Animation fade2 = AnimationUtils.loadAnimation(this,R.anim.fade_in2);
    logo2.startAnimation(fade2);
    fade2.setAnimationListener(new AnimationListener(){
        public void onAnimationEnd(Animation animation){
            startActivity(new   
             Intent(AnimatedSplashScreenActivity.this,MainActivity.class));
            AnimatedSplashScreenActivity.this.finish();
        }
         public void onAnimationRepeat(Animation animation){
    }
        public void onAnimationStart(Animation animation){
        }

});
    Animation spinin=AnimationUtils.loadAnimation(this,R.anim.custom_anim);
    LayoutAnimationController controller=new LayoutAnimationController(spinin);
    TableLayout table=(TableLayout) findViewById(R.id.TableLayout01);
    for(int i=0;i<table.getChildCount();i++)
    {
        TableRow row =(TableRow) table.getChildAt(i);
        row.setLayoutAnimation(controller);

    }
}
@Override
protected void onPause()
{
    super.onPause();
    TextView logo1=(TextView) findViewById(R.id.TextViewTopTitle);
    logo1.clearAnimation();
    TextView logo2=(TextView) findViewById(R.id.TextViewBottomTitle);
    logo2.clearAnimation();
    TableLayout table=(TableLayout) findViewById(R.id.TableLayout01);
    for(int i=0;i<table.getChildCount();i++)
    {
        TableRow row =(TableRow) table.getChildAt(i);
        row.clearAnimation();

    }
}
@Override
protected void onResume()
{
    super.onResume();

    startAnimating();

}

}
<uses-sdk android:minSdkVersion="10" />

<application
    android:icon="@drawable/icon"
    android:label="@string/app_name" >
    <activity
        android:name=".AnimatedSplashScreenActivity"
        android:label="@string/app_name" >
        <intent-filter>
            <action android:name="android.intent.action.MAIN" />

            <category android:name="android.intent.category.LAUNCHER" />
        </intent-filter>
    </activity>
<activity android:name=".MainActivity"
    android:label="@string/hello">
    <intent-filter>
        <action android:name="com.animated.splash.MainActivity"/>
        <category android:name="android.intent.category.DEFAULT"/>
    </intent-filter>
</activity>    

</application>

</manifest>
这是AnimatedSplashScreenActivity.java文件。
包com.animated.splash;
导入android.app.Activity;
导入android.content.Intent;
导入android.os.Bundle;
导入android.view.animation.animation;
导入android.view.animation.AnimationUtils;
导入android.view.animation.LayoutAnimationController;
导入android.view.animation.animation.AnimationListener;
导入android.widget.TableLayout;
导入android.widget.TableRow;
导入android.widget.TextView;
公共类AnimatedSplashScreenActivity扩展活动{
/**在首次创建活动时调用*/
@凌驾
创建时的公共void(Bundle savedInstanceState){
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
startAnimating();
}
/** 
*在启动屏幕上启动动画的帮助器方法
*/
私有void startAnimating()
{
//淡入榜首
TextView logo1=(TextView)findViewById(R.id.TextViewTopTitle);
Animation fade1=AnimationUtils.loadAnimation(这是R.anim.fade_in);
标识1.开始激活(fade1);
TextView logo2=(TextView)findViewById(R.id.TextViewBottomTitle);
Animation fade2=AnimationUtils.loadAnimation(这是R.anim.fade_in2);
标识2.开始激活(fade2);
setAnimationListener(新的AnimationListener(){
onAnimationEnd上的公共无效(动画){
星触觉(新)
意图(AnimatedSplashScreenActivity.this,MainActivity.class));
AnimatedSplashScreenActivity.this.finish();
}
onAnimationRepeat上的公共无效(动画){
}
onAnimationStart上的公共无效(动画){
}
});
Animation spinin=AnimationUtils.loadAnimation(this,R.anim.custom_anim);
LayoutImationController=新的LayoutImationController(spinin);
TableLayout table=(TableLayout)findviewbyd(R.id.TableLayout01);

对于(int i=0;i您正在将内容视图设置为
main.xml
。但是您正在获取在
splash.xml
中定义的TextView
R.id.TextViewTopTitle
。请尝试将内容视图设置为
splash.xml

<uses-sdk android:minSdkVersion="10" />

<application
    android:icon="@drawable/icon"
    android:label="@string/app_name" >
    <activity
        android:name=".AnimatedSplashScreenActivity"
        android:label="@string/app_name" >
        <intent-filter>
            <action android:name="android.intent.action.MAIN" />

            <category android:name="android.intent.category.LAUNCHER" />
        </intent-filter>
    </activity>
<activity android:name=".MainActivity"
    android:label="@string/hello">
    <intent-filter>
        <action android:name="com.animated.splash.MainActivity"/>
        <category android:name="android.intent.category.DEFAULT"/>
    </intent-filter>
</activity>    

</application>

</manifest>
@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.splash);
    startAnimating();
}

您正在将内容视图设置为
main.xml
。但是您正在获取在
splash.xml
中定义的TextView
R.id.TextViewTopTitle
。请尝试将内容视图设置为
splash.xml

<uses-sdk android:minSdkVersion="10" />

<application
    android:icon="@drawable/icon"
    android:label="@string/app_name" >
    <activity
        android:name=".AnimatedSplashScreenActivity"
        android:label="@string/app_name" >
        <intent-filter>
            <action android:name="android.intent.action.MAIN" />

            <category android:name="android.intent.category.LAUNCHER" />
        </intent-filter>
    </activity>
<activity android:name=".MainActivity"
    android:label="@string/hello">
    <intent-filter>
        <action android:name="com.animated.splash.MainActivity"/>
        <category android:name="android.intent.category.DEFAULT"/>
    </intent-filter>
</activity>    

</application>

</manifest>
@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.splash);
    startAnimating();
}

你发布了除了logcat之外的所有东西,你应该需要什么呢?你发布了除了logcat之外的所有东西,你应该需要什么呢我更改了您答案的格式…我将其作为提高可读性的建议。经常看到代码比描述代码要好。请不要生气,如果您不喜欢,可以将答案返回到原始格式。@sam:我愿意接受可以学习的建议。因此,感谢您的编辑。:(Upvote)我更改了您答案的格式…我将其作为提高可读性的建议提供。经常查看代码比描述代码要好。请不要生气,如果您不喜欢,可以将答案返回到原始格式。@sam:我愿意接受可以学习的建议。因此,感谢您的编辑。:)
<ImageView android:id="@+id/ImageView3_Right" android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical|center_horizontal"
android:src="@drawable/splash4"></ImageView>     
<TextView  
android:layout_width="fill_parent" 
android:layout_height="wrap_content" 
android:id="@+id/TextViewBottomTitle" android:text="@string/app_logo_bottom"
android:gravity="center" android:textSize="25pt">
</TextView>

<TextView android:id="@+id/TextViewBottomVersion"   
android:text="@string/app_version_info"
android:textSize="5pt" android:layout_height="wrap_content"
android:lineSpacingExtra="4pt" android:layout_width="fill_parent" 
android:layout_gravity="center_vertical|center_horizontal"
android:gravity="center" >
</TextView>

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

<TextView
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:text="Main Screen" />

</LinearLayout>
@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.splash);
    startAnimating();
}