Android应用程序在添加动画时停止

时间:2013-04-06 19:54:15

标签: java android xml android-emulator android-animation

我是初学者在android和编码小游戏介绍屏幕。我的问题是,当我向介绍屏幕添加一些基本动画时,没有输出,应用程序停止弹出,如enter image description here

当我评论动画方法它显示简单的基于xml的布局请帮助我在哪里问题在这里是我的java文件

public class MainActivity extends Activity 
{
TextView  logo ;
TextView bottom  ;   
@Override
protected void onCreate(Bundle savedInstanceState)
{   
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);
    animate();
}
public void animate()
{  
    logo=  (TextView) findViewById(R.id.toplogo);
    bottom =(TextView) findViewById(R.id.footer);
    Animation fade1= AnimationUtils.loadAnimation(this, R.anim.fade_in);
    logo.setAnimation(fade1);

    Animation fade2=  AnimationUtils.loadAnimation(this, R.anim.fade_in2);
    bottom.setAnimation(fade2);

    fade2.setAnimationListener(new AnimationListener(){

        @Override
        public void onAnimationEnd(Animation animation)
        {
           startActivity(new  Intent(MainActivity.this, Menu.class));    
           MainActivity.this.finish();  
        }

        @Override
        public void onAnimationRepeat(Animation animation) {
            // TODO Auto-generated method stub

        }

        @Override
        public void onAnimationStart(Animation animation) {
            // TODO Auto-generated method stub
    }}
    );

 }     
public void onpause()
{
    super.onPause();
    logo.clearAnimation();
    bottom.clearAnimation();        
}
public void onResume()
{
    super.onResume();
    animate();
}

}

activity_main.xml file

<LinearLayout       xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="@android:color/black"
>

<TextView
    android:id="@+id/toplogo"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:text="@string/hello_world"
    android:textColor="@color/logoname"
    android:gravity="top|center"
    android:textSize="@dimen/logosize" />

<TableLayout
    android:id="@+id/TableLayout01"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:stretchColumns="*" >

    <TableRow
        android:id="@+id/tableRow1"
         android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_gravity="center_vertical|center_horizontal"
             android:minHeight="150px"               
            >
        <ImageView
            android:id="@+id/imageView1"
            android:layout_width="wrap_content"
            android:layout_height="fill_parent"
            android:layout_gravity="center_vertical|center_horizontal"
            android:src="@drawable/splash1"
              />

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

    </TableRow>

    <TableRow
        android:id="@+id/tableRow2"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:minHeight="150px"               

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

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




</TableLayout>

<TextView
    android:id="@+id/footer"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:textColor="@color/logoname"
    android:textSize="@dimen/logosize"
    android:text="Done That " 
    android:gravity="bottom|center"
    android:minHeight="120px"
     >
  </TextView>

   </LinearLayout>

动画文件

   fade_in2.xml
   <?xml version="1.0" encoding="utf-8"?>
  <set  xmlns:android="http://schemas.android.com/apk/res/android"
 android:shareInterpolator="false">
  <alpha
    android:fromAlpha="0.0"
    android:toAlpha="1.0"
    android:duration="2500"
    android:startOffset="2500">
 </alpha>

 </set >

同样的方式fade_in.xml等。请帮助我解决与animation无法使用的逻辑/代码有关的问题。

编辑错误日志..

我不确定我是否复制了所需的一个请看这一个(我从logcat标签下拉选择了错误)

04-06 20:18:25.996: E/AndroidRuntime(812): FATAL EXCEPTION: main
04-06 20:18:25.996: E/AndroidRuntime(812): android.content.ActivityNotFoundException: Unable to find explicit activity class {com.example.simplegame/android.view.Menu}; have you declared this activity in your AndroidManifest.xml?
04-06 20:18:25.996: E/AndroidRuntime(812):  at android.app.Instrumentation.checkStartActivityResult(Instrumentation.java:1618)
04-06 20:18:25.996: E/AndroidRuntime(812):  at android.app.Instrumentation.execStartActivity(Instrumentation.java:1417)
04-06 20:18:25.996: E/AndroidRuntime(812):  at android.app.Activity.startActivityForResult(Activity.java:3370)
04-06 20:18:25.996: E/AndroidRuntime(812):  at android.app.Activity.startActivityForResult(Activity.java:3331)
04-06 20:18:25.996: E/AndroidRuntime(812):  at android.app.Activity.startActivity(Activity.java:3566)
04-06 20:18:25.996: E/AndroidRuntime(812):  at android.app.Activity.startActivity(Activity.java:3534)
04-06 20:18:25.996: E/AndroidRuntime(812):  at com.example.simplegame.MainActivity$1.onAnimationEnd(MainActivity.java:41)
04-06 20:18:25.996: E/AndroidRuntime(812):  at android.view.animation.AnimationSet.getTransformation(AnimationSet.java:400)
04-06 20:18:25.996: E/AndroidRuntime(812):  at android.view.animation.Animation.getTransformation(Animation.java:940)
04-06 20:18:25.996: E/AndroidRuntime(812):  at android.view.View.drawAnimation(View.java:13205)
04-06 20:18:25.996: E/AndroidRuntime(812):  at android.view.View.draw(View.java:13344)
04-06 20:18:25.996: E/AndroidRuntime(812):  at android.view.ViewGroup.drawChild(ViewGroup.java:2928)
04-06 20:18:25.996: E/AndroidRuntime(812):  at android.view.ViewGroup.dispatchDraw(ViewGroup.java:2797)
04-06 20:18:25.996: E/AndroidRuntime(812):  at android.view.View.draw(View.java:13715)
04-06 20:18:25.996: E/AndroidRuntime(812):  at android.view.View.draw(View.java:13596)
04-06 20:18:25.996: E/AndroidRuntime(812):  at android.view.ViewGroup.drawChild(ViewGroup.java:2928)
04-06 20:18:25.996: E/AndroidRuntime(812):  at android.view.ViewGroup.dispatchDraw(ViewGroup.java:2797)
04-06 20:18:25.996: E/AndroidRuntime(812):  at android.view.View.draw(View.java:13715)  
04-06 20:18:25.996: E/AndroidRuntime(812):  at android.widget.FrameLayout.draw(FrameLayout.java:467)
04-06 20:18:25.996: E/AndroidRuntime(812):  at android.view.View.draw(View.java:13596)
04-06 20:18:25.996: E/AndroidRuntime(812):  at android.view.ViewGroup.drawChild(ViewGroup.java:2928)
04-06 20:18:25.996: E/AndroidRuntime(812):  at android.view.ViewGroup.dispatchDraw(ViewGroup.java:2797)
04-06 20:18:25.996: E/AndroidRuntime(812):  at android.view.View.draw(View.java:13594)
04-06 20:18:25.996: E/AndroidRuntime(812):  at android.view.ViewGroup.drawChild(ViewGroup.java:2928)
04-06 20:18:25.996: E/AndroidRuntime(812):  at an  droid.view.ViewGroup.dispatchDraw(ViewGroup.java:2797)
04-06 20:18:25.996: E/AndroidRuntime(812):  at android.view.View.draw(View.java:13715)
04-06 20:18:25.996: E/AndroidRuntime(812):  at android.widget.FrameLayout.draw(FrameLayout.java:467)
04-06 20:18:25.996: E/AndroidRuntime(812):  at com.android.internal.policy.impl.PhoneWindow$DecorView.draw(PhoneWindow.java:2211)
04-06 20:18:25.996: E/AndroidRuntime(812):  at android.view.ViewRootImpl.drawSoftware(ViewRootImpl.java:2281)
04-06 20:18:25.996: E/AndroidRuntime(812):  at  android.view.ViewRootImpl.draw(ViewRootImpl.java:2177)
04-06 20:18:25.996: E/AndroidRuntime(812):  at android.view.ViewRootImpl.performDraw(ViewRootImpl.java:2045)
04-06 20:18:25.996: E/AndroidRuntime(812):  at android.view.ViewRootImpl.performTraversals(ViewRootImpl.java:1854)
04-06 20:18:25.996: E/AndroidRuntime(812):  at android.view.ViewRootImpl.doTraversal(ViewRootImpl.java:989)
04-06 20:18:25.996: E/AndroidRuntime(812):  at android.view.ViewRootImpl$TraversalRunnable.run(ViewRootImpl.java:4351)
04-06 20:18:25.996: E/AndroidRuntime(812):  at android.view.Choreographer$CallbackRecord.run(Choreographer.java:749)
04-06 20:18:25.996: E/AndroidRuntime(812):  at android.view.Choreographer.doCallbacks(Choreographer.java:562)
04-06 20:18:25.996: E/AndroidRuntime(812):  at android.view.Choreographer.doFrame(Choreographer.java:532)
04-06 20:18:25.996: E/AndroidRuntime(812):  at android.view.Choreographer$FrameDisplayEventReceiver.run(Choreographer.java:735)
04-06 20:18:25.996: E/AndroidRuntime(812):  at android.os.Handler.handleCallback(Handler.java:725)
04-06 20:18:25.996: E/AndroidRuntime(812):  at android.os.Handler.dispatchMessage(Handler.java:92)
04-06 20:18:25.996: E/AndroidRuntime(812):  at android.os.Looper.loop(Looper.java:137)
04-06 20:18:25.996: E/AndroidRuntime(812):  at android.app.ActivityThread.main(ActivityThread.java:5041)
04-06 20:18:25.996: E/AndroidRuntime(812):  at java.lang.reflect.Method.invokeNative(Native Method)
04-06 20:18:25.996: E/AndroidRuntime(812):  at java.lang.reflect.Method.invoke(Method.java:511)
04-06 20:18:25.996: E/AndroidRuntime(812):  at  com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:793)
04-06 20:18:25.996: E/AndroidRuntime(812):  at     com.android.internal.os.ZygoteInit.main(ZygoteInit.java:560)
04-06 20:18:25.996: E/AndroidRuntime(812):  at dalvik.system.NativeStart.main(Native       Method)

编辑Manifest.xml

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

 <uses-sdk
 android:minSdkVersion="8"
 android:targetSdkVersion="17" />

 <application
 android:allowBackup="true"
 android:icon="@drawable/ic_launcher"
 android:label="@string/app_name"
 android:theme="@style/AppTheme" >
 <activity
  android:name="com.example.simplegame.MainActivity"
  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="Menu"></activity>
   </application>     

  </manifest>

3 个答案:

答案 0 :(得分:2)

问题是你没有在你的清单中声明活动

04-06 20:18:25.996: E/AndroidRuntime(812): android.content.ActivityNotFoundException: Unable to find explicit activity class {com.example.simplegame/android.view.Menu}; have you declared this activity in your AndroidManifest.xml?

<强>已更新

将此添加到您的清单中。并将包名称替换为您的包名称,例如com.etc.xxx

    <activity
        android:name="*package name*.Menu"
        android:label="@string/app_name" >
        <intent-filter>
            <action android:name="android.intent.action.MENU" />
            <category android:name="android.intent.category.DEFAULT" />
        </intent-filter>
    </activity>

答案 1 :(得分:1)

您未在AndroidManifest.xml

中创建活动

此链接可以帮助您:Best way to add Activity to an Android project in Eclipse?

记住Google是你的朋友,努力学习自己的东西,从长远来看,它会让你受益。

答案 2 :(得分:1)

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

 <uses-sdk
  android:minSdkVersion="8"
  android:targetSdkVersion="17" />

 <application
  android:allowBackup="true"
  android:icon="@drawable/ic_launcher"
  android:label="@string/app_name"
  android:theme="@style/AppTheme" >

   <activity
       android:name="com.example.simplegame.INTRO"
       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= "com.example.simplegame.Menu" <!-- java file-->
       android:label="@string/app_name">
       <intent-filter>
         <action android:name="thePackageOfTheLayoutsXmlFiles.MENU"/> <!-- layout -->
         <category androi:name = "android.intent.category.DEFAULT"/>
      </intent-filter>
   </activity>
 </application>     
 </manifest>

在清单文件中,您忘记将布局引用到java文件中。 此外,当您想要向应用添加新活动时,您需要创建一个新的xml文件 对于layout ..和新的java类,这个类应该扩展Activity 然后将onCreate()方法添加到此类..