0

我有这个用于启动画面的代码。当我运行它时,它在模拟器上显示错误,因为“应用程序动画闪屏(进程 com.animated.splash)已意外停止。请重试。”

我在这里附上整个代码。

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>

这是 custom_anim.xml

<?xml version="1.0" encoding="UTF-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android">
    <alpha android:fromAlpha="0.0" android:toAlpha="1.0" 
                     android:interpolator="@android:anim/accelerate_interpolator" 
                android:duration="6000" android:repeatCount="infinite"/>
    </set>

这是fade_in.xml

    <?xml version="1.0" encoding="UTF-8"?>
   <set xmlns:android="http://schemas.android.com/apk/res/android">
    <alpha android:fromAlpha="0.0" android:toAlpha="1.0"  
    android:interpolator="@android:anim/accelerate_interpolator" 
    android:duration="3000" android:repeatCount="infinite"/>
 </set>

这是fade_in2.xml

<?xml version="1.0" encoding="UTF-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android">
    <alpha android:fromAlpha="0.0" android:toAlpha="1.0"
    android:interpolator="@android:anim/accelerate_interpolator" 
    android:duration="5000" android:repeatCount="infinite"/>
    </set>

这是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"
>
<TextView  
android:layout_width="fill_parent" 
android:layout_height="wrap_content" 
android:id="@+id/TextViewTopTitle" android:text="@string/app_logo_top"
android:layout_gravity="center_vertical|center_horizontal"
android:gravity="top|center" android:textSize="25pt">
</TextView>
<TableLayout android:id="@+id/TableLayout01" android:stretchColumns="*"
android:layout_height="wrap_content" android:layout_width="fill_parent">
<TableRow android:id="@+id/TableRow01" android:layout_height="wrap_content"
android:layout_width="wrap_content" 
android:layout_gravity="center_vertical|center_horizontal">
<ImageView android:id="@+id/ImageView2_Left" android:layout_width="wrap_content"
android:layout_height="wrap_content"  
android:layout_gravity="center_vertical|center_horizontal"
android:src="@drawable/splash1"></ImageView>

<ImageView android:id="@+id/ImageView2_Right" android:layout_width="wrap_content"
android:layout_height="wrap_content" 
android:layout_gravity="center_vertical|center_horizontal"
android:src="@drawable/splash2"></ImageView>     

<TableRow android:id="@+id/TableRow02" android:layout_height="wrap_content"
android:layout_width="wrap_content"
android:layout_gravity="center_vertical|center_horizontal">

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

最后是 main.xml

<?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>
4

1 回答 1

4

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

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.splash);
    startAnimating();
}
于 2012-07-06T18:53:02.013 回答