带动画的启动活动不起作用

时间:2014-11-07 16:33:50

标签: java android android-intent

我尝试在启动活动中使用动画,但动画启动和运行意图(启动新活动)应用程序崩溃。 看我的Splash活动:

package com.skyline.paranorman;

import android.os.Bundle;
import android.os.Handler;
import android.app.Activity;
import android.content.Intent;
import android.graphics.drawable.AnimationDrawable;
import android.view.Menu;
import android.widget.ImageView;

public class Splash extends Activity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_splash);
        final ImageView img = (ImageView) findViewById(R.id.imageView1);
        img.setBackgroundResource(R.anim.animation);
        img.setImageDrawable(null);
        AnimationDrawable anim = (AnimationDrawable) img.getBackground();
        anim.start();

        Thread background = new Thread() {
            public void run() {

                try {
                    sleep(5*1000);

                } catch (Exception e) {
                    e.printStackTrace();
                }finally{
                    // After 5 seconds redirect to another intent
                    Intent i=new Intent(getBaseContext(),MainActivity.class);
                    startActivity(i);

                    //Remove activity
                    finish();
                }
            }
        };

        // start thread
        background.start();



    }


    @Override
    public boolean onCreateOptionsMenu(Menu menu) {
        // Inflate the menu; this adds items to the action bar if it is present.
        getMenuInflater().inflate(R.menu.splash, menu);
        return true;
    }

}

我的LogCat

11-07 11:32:16.106: E/AndroidRuntime(968): FATAL EXCEPTION: main
11-07 11:32:16.106: E/AndroidRuntime(968): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.skyline.paranorman/com.skyline.paranorman.MainActivity}: android.view.InflateException: Binary XML file line #52: Error inflating class <unknown>
11-07 11:32:16.106: E/AndroidRuntime(968):  at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2211)
11-07 11:32:16.106: E/AndroidRuntime(968):  at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2261)
11-07 11:32:16.106: E/AndroidRuntime(968):  at android.app.ActivityThread.access$600(ActivityThread.java:141)
11-07 11:32:16.106: E/AndroidRuntime(968):  at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1256)
11-07 11:32:16.106: E/AndroidRuntime(968):  at android.os.Handler.dispatchMessage(Handler.java:99)
11-07 11:32:16.106: E/AndroidRuntime(968):  at android.os.Looper.loop(Looper.java:137)
11-07 11:32:16.106: E/AndroidRuntime(968):  at android.app.ActivityThread.main(ActivityThread.java:5103)
11-07 11:32:16.106: E/AndroidRuntime(968):  at java.lang.reflect.Method.invokeNative(Native Method)
11-07 11:32:16.106: E/AndroidRuntime(968):  at java.lang.reflect.Method.invoke(Method.java:525)
11-07 11:32:16.106: E/AndroidRuntime(968):  at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:737)
11-07 11:32:16.106: E/AndroidRuntime(968):  at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:553)
11-07 11:32:16.106: E/AndroidRuntime(968):  at dalvik.system.NativeStart.main(Native Method)
11-07 11:32:16.106: E/AndroidRuntime(968): Caused by: android.view.InflateException: Binary XML file line #52: Error inflating class <unknown>
11-07 11:32:16.106: E/AndroidRuntime(968):  at android.view.LayoutInflater.createView(LayoutInflater.java:620)
11-07 11:32:16.106: E/AndroidRuntime(968):  at com.android.internal.policy.impl.PhoneLayoutInflater.onCreateView(PhoneLayoutInflater.java:56)
11-07 11:32:16.106: E/AndroidRuntime(968):  at android.view.LayoutInflater.onCreateView(LayoutInflater.java:669)
11-07 11:32:16.106: E/AndroidRuntime(968):  at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:694)
11-07 11:32:16.106: E/AndroidRuntime(968):  at android.view.LayoutInflater.rInflate(LayoutInflater.java:755)
11-07 11:32:16.106: E/AndroidRuntime(968):  at android.view.LayoutInflater.inflate(LayoutInflater.java:492)
11-07 11:32:16.106: E/AndroidRuntime(968):  at android.view.LayoutInflater.inflate(LayoutInflater.java:397)
11-07 11:32:16.106: E/AndroidRuntime(968):  at android.view.LayoutInflater.inflate(LayoutInflater.java:353)
11-07 11:32:16.106: E/AndroidRuntime(968):  at com.android.internal.policy.impl.PhoneWindow.setContentView(PhoneWindow.java:267)
11-07 11:32:16.106: E/AndroidRuntime(968):  at com.actionbarsherlock.internal.ActionBarSherlockNative.setContentView(ActionBarSherlockNative.java:119)
11-07 11:32:16.106: E/AndroidRuntime(968):  at com.actionbarsherlock.app.SherlockActivity.setContentView(SherlockActivity.java:218)
11-07 11:32:16.106: E/AndroidRuntime(968):  at com.skyline.paranorman.MainActivity.onCreate(MainActivity.java:33)
11-07 11:32:16.106: E/AndroidRuntime(968):  at android.app.Activity.performCreate(Activity.java:5133)
11-07 11:32:16.106: E/AndroidRuntime(968):  at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1087)
11-07 11:32:16.106: E/AndroidRuntime(968):  at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2175)
11-07 11:32:16.106: E/AndroidRuntime(968):  ... 11 more
11-07 11:32:16.106: E/AndroidRuntime(968): Caused by: java.lang.reflect.InvocationTargetException
11-07 11:32:16.106: E/AndroidRuntime(968):  at java.lang.reflect.Constructor.constructNative(Native Method)
11-07 11:32:16.106: E/AndroidRuntime(968):  at java.lang.reflect.Constructor.newInstance(Constructor.java:417)
11-07 11:32:16.106: E/AndroidRuntime(968):  at android.view.LayoutInflater.createView(LayoutInflater.java:594)
11-07 11:32:16.106: E/AndroidRuntime(968):  ... 25 more
11-07 11:32:16.106: E/AndroidRuntime(968): Caused by: java.lang.OutOfMemoryError
11-07 11:32:16.106: E/AndroidRuntime(968):  at android.graphics.BitmapFactory.nativeDecodeAsset(Native Method)
11-07 11:32:16.106: E/AndroidRuntime(968):  at android.graphics.BitmapFactory.decodeStream(BitmapFactory.java:503)
11-07 11:32:16.106: E/AndroidRuntime(968):  at android.graphics.BitmapFactory.decodeResourceStream(BitmapFactory.java:356)
11-07 11:32:16.106: E/AndroidRuntime(968):  at android.graphics.drawable.Drawable.createFromResourceStream(Drawable.java:800)
11-07 11:32:16.106: E/AndroidRuntime(968):  at android.content.res.Resources.loadDrawable(Resources.java:2105)
11-07 11:32:16.106: E/AndroidRuntime(968):  at android.content.res.TypedArray.getDrawable(TypedArray.java:601)
11-07 11:32:16.106: E/AndroidRuntime(968):  at android.widget.ImageView.<init>(ImageView.java:127)
11-07 11:32:16.106: E/AndroidRuntime(968):  at android.widget.ImageView.<init>(ImageView.java:117)
11-07 11:32:16.106: E/AndroidRuntime(968):  ... 28 more

和我的activity_main.xml

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:background="#000000"
    tools:context=".MainActivity" >

    <RelativeLayout
        android:id="@+id/linearLayout1"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentBottom="true"
        android:layout_alignParentLeft="true"
        android:layout_alignParentRight="true"
        android:background="#000" >

        <ImageView
            android:id="@+id/nextimg"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_alignParentRight="true"
            android:layout_alignParentTop="true"
            android:src="@drawable/ic_action_next" />

        <ImageView
            android:id="@+id/backimg"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_alignParentLeft="true"
            android:layout_centerVertical="true"
            android:src="@drawable/ic_action_back" />

        <View
            android:layout_width="fill_parent"
            android:layout_height="1dip"
            android:layout_alignParentLeft="true"
            android:layout_alignParentTop="true"
            android:background="#33b5e5" />

        <TextView
            android:id="@+id/tvPage"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_centerHorizontal="true"
            android:layout_centerVertical="true"
            android:text="@string/bookname"
            android:textAppearance="?android:attr/textAppearanceMedium"
            android:textColor="#33b5e5" />

    </RelativeLayout>

    <ImageView
        android:id="@+id/imageView1"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_above="@+id/linearLayout1"
        android:layout_alignParentLeft="true"
        android:layout_alignParentRight="true"
        android:layout_alignParentTop="true"
        android:src="@drawable/poster" />

</RelativeLayout>

更新: 当我从启动活动中删除动画时,通常会启动它!

0 个答案:

没有答案