0

スプラッシュスクリーン用のこのコードがあります。実行すると、エミュレーターに「アプリケーションのanimatedsplashscreen(プロセス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 に答える