package com.androidbook.triviaquiz;
import android.content.Intent;
import android.os.Bundle;
import android.util.Log;
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 QuizSplashActivity extends TriviaQuizActivity{
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.splash);
Log.e("My App","Error Occured in on create1");
startAnimating();
Log.e("My App","Error Occured in on create1");
}
public void startAnimating() {
try{
TextView logo1 = (TextView) findViewById(R.id.textView1);
Animation fade1 = AnimationUtils.loadAnimation(this, R.anim.fade_in);
logo1.startAnimation(fade1);
Log.e("My App","Error Occured in start animating1");
TextView logo2 = (TextView) findViewById(R.id.textView2);
Animation fade2 = AnimationUtils.loadAnimation(this, R.anim.fade_in2);
logo2.startAnimation(fade2);
Log.e("My App","Error Occured in start animating2");
fade2.setAnimationListener(new AnimationListener() {
public void onAnimationEnd(Animation animation) {
// The animation has ended, transition to the Main Menu screen
startActivity(new Intent(QuizSplashActivity.this, QuizMenuActivity.class));
QuizSplashActivity.this.finish();
}
public void onAnimationRepeat(Animation animation) {
}
public void onAnimationStart(Animation animation) {
}
});
Log.e("My App","Error Occured in start animating general");
Animation spinin = AnimationUtils.loadAnimation(this, R.anim.custom_anim);
LayoutAnimationController controller =
new LayoutAnimationController(spinin);
TableLayout table = (TableLayout) findViewById(R.id.tableLayout1);
for (int i = 0; i < table.getChildCount(); i++) {
TableRow row = (TableRow) table.getChildAt(i);
row.setLayoutAnimation(controller);
Log.e("My App","Error Occured in start animating general end ");
}
}
catch(Exception ex)
{
Log.e("Exception logged",ex.getStackTrace().toString());
}
}
@Override
public void onPause() {
super.onPause();
TextView logo1 = (TextView) findViewById(R.id.textView1);
logo1.clearAnimation();
Log.e("My App","Error Occured in onPause1");
TextView logo2 = (TextView) findViewById(R.id.textView2);
logo2.clearAnimation();
Log.e("My App","Error Occured in onPause1");
TableLayout table = (TableLayout) findViewById(R.id.tableLayout1);
for (int i = 0; i < table.getChildCount(); i++) {
TableRow row = (TableRow) table.getChildAt(i);
row.clearAnimation();
Log.e("My App","Error Occured in onPause3");
}
}
@Override
public void onResume(){
super.onResume();
startAnimating();
}
}
这是清单文件
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.androidbook.triviaquiz"
android:versionCode="1"
android:versionName="1.0">
<uses-sdk android:minSdkVersion="7" />
<application android:icon="@drawable/quizicon" android:label="@string/app_name" android:debuggable="true">
<activity android:name=".QuizSplashActivity" android:label="@string/splash">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity android:name="QuizGameActivty" android:label="@string/game"></activity>
<activity android:name="QuizHelpActivity" android:label="@string/help"></activity>
<activity android:name="QuizMenuActivity" android:label="@string/menu"></activity>
<activity android:name="QuizScoresActivity" android:label="@string/scores"></activity>
<activity android:name="QuizsettingsActivity" android:label="@string/settings"></activity>
</application>
</manifest>
在调试模式下抛出的异常:
{com.androidbook.triviaquiz/com.androidbook.triviaquiz.QuizSplashActivity}: java.lang.ClassCastException: android.widget.TextView
布局文件启动活动
<?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:weightSum="1">
<LinearLayout android:layout_width="fill_parent" android:id="@+id/linearLayout1" android:layout_height="wrap_content" android:orientation="vertical" android:background="@android:color/black" android:layout_weight="0.94" android:weightSum="1">
<TextView android:layout_height="wrap_content" android:layout_width="fill_parent" android:layout_weight="0.08" android:text="@string/header" android:textColor="@color/logo_color" android:textSize="24pt" android:id="@+id/textView1"></TextView>
<TableLayout android:layout_width="fill_parent" android:layout_height="wrap_content" android:id="@+id/tableLayout1" android:layout_weight="0.48" android:weightSum="1" android:stretchColumns="*">
<TableRow android:id="@+id/tableRow1" android:layout_height="wrap_content" android:layout_width="fill_parent">
<ImageView android:src="@drawable/splash1" android:id="@+id/imageView1" android:layout_height="wrap_content" android:layout_width="fill_parent"></ImageView>
<ImageView android:src="@drawable/splash2" android:id="@+id/imageView2" android:layout_width="wrap_content" android:layout_height="wrap_content"></ImageView>
</TableRow>
<TableRow android:id="@+id/tableRow2" android:layout_height="wrap_content" android:layout_width="fill_parent">
<ImageView android:src="@drawable/splash3" android:id="@+id/imageView3" android:layout_width="wrap_content" android:layout_height="wrap_content"></ImageView>
<ImageView android:src="@drawable/splash4" android:id="@+id/imageView4" android:layout_width="wrap_content" android:layout_height="wrap_content"></ImageView>
</TableRow>
<TextView android:layout_height="wrap_content" android:id="@+id/textView2" android:layout_width="fill_parent" android:textColor="@color/logo_color" android:fadeScrollbars="true" android:focusableInTouchMode="true" android:textSize="24pt" android:text="@string/footer" android:layout_weight="0.36"></TextView>
</TableLayout>
<TextView android:layout_width="fill_parent" android:text="@string/version" android:background="@color/version_bkgrd" android:textColor="@color/version_color" android:id="@+id/textView3" android:layout_gravity="center_horizontal" android:layout_height="32dp" android:lineSpacingExtra="@dimen/version_spacing"></TextView>
</LinearLayout>
</LinearLayout>
答案 0 :(得分:0)
嗯,一切看起来很好......但是我还是想让你检查两个地方: