如何启动画面名为.gif动画文件连接? [英] How to connect splash screen with .gif animation file?

查看:234
本文介绍了如何启动画面名为.gif动画文件连接?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经开发了一个播放音乐的应用程序时按钮,用户presses。而且我还开发了一个闪屏的应用程序一起,并没有与应用工作。不过,我想修改我的应用程序,以便启动画面播放gif文件,而不是常规的形象。当我试图.gif文件创建新的项目它没有工作。我用电影类的。我想不是出于我的闪屏,使其调用gif.java文件。但它并没有奏效。它只是向我展示了我的GIF文件的失真的图像。比它说
您的应用程序崩溃了。我主要的Java,闪屏和gif .java文件和manifest.xml的有以下几种。

I have developed an app that plays a music when the user presses on button. And I have also developed a splash screen along with the app and it did work with the app. However, I want to modify my app so that splash screen plays gif file instead of regular image. When I tried .gif file by creating new project it did worked. I used movie class for that. I tried intent for my splash screen so that it calls gif.java file. But it did not worked. It just showed me the distorted image of my gif file. And than It said "Your APP HAS CRASHED". My main java, splash screen and gif .java files and manifest.xml are the following.

主要的Java

import android.app.Activity;
import android.content.Intent;
import android.media.AudioManager;
import android.media.MediaPlayer;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;




    public class MainActivity extends Activity implements OnClickListener {
        private MediaPlayer mp;

       @Override
       public void onCreate(Bundle savedInstanceState) { 
           super.onCreate(savedInstanceState);
          setContentView(R.layout.activity_main);
          setContentView(new MYGIFView (this));
          setVolumeControlStream(AudioManager.STREAM_MUSIC);
          findViewById(R.id.button_1).setOnClickListener(this);
          findViewById(R.id.button_2).setOnClickListener(this);
          findViewById(R.id.button_3).setOnClickListener(this);
       }
       public void onClick(View v) {   
           int resId=1;

       // Release any resources from previous MediaPlayer
          if (mp != null) {   
              mp.release(); 
          } 

          switch (v.getId()) {
          case R.id.button_1: resId = R.raw.button_1; break;
          case R.id.button_2: resId = R.raw.button_2; break;
          case R.id.button_3:
             startActivity(new Intent(MainActivity.this,SecondActivity.class));
             return;

          }

       // Create a new MediaPlayer to play this sound
          mp = MediaPlayer.create(this, resId); 
          mp.start();
       }
    }

开机画面。 java的

Splash Screen. java

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.os.Handler;

public class SplashScreen extends Activity {

    // Splash screen timer
    private static int SPLASH_TIME_OUT = 3000;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);

        new Handler().postDelayed(new Runnable() {

            /*
             * Showing splash screen with a timer. This will be useful when you
             * want to show case your app logo / company
             */

            @Override
            public void run() {
                // This method will be executed once the timer is over
                // Start your app main activity
                Intent i = new Intent(SplashScreen.this, MYGIFView.class);
                startActivity(i);

                // close this activity
                finish();
            }
        }, SPLASH_TIME_OUT);
    }

}

MYGIF.java

MYGIF.java

import java.io.InputStream;
import android.content.Context;
import android.graphics.Canvas;
import android.graphics.Color;
import android.graphics.Movie;
import android.view.View;

class MYGIFView extends View{

Movie movie,movie1;
InputStream is=null,is1=null;
long moviestart;
public MYGIFView(Context context) {
super(context);




is=context.getResources().openRawResource(R.drawable.th_welcome);
movie=Movie.decodeStream(is);

}

@Override
protected void onDraw(Canvas canvas) {

canvas.drawColor(Color.BLACK);
super.onDraw(canvas);
long now=android.os.SystemClock.uptimeMillis();
System.out.println("now="+now);
if (moviestart == 0) { // first time
moviestart = now;

}
System.out.println("\tmoviestart="+moviestart);
int relTime = (int)((now - moviestart) % movie.duration()) ;
System.out.println("time="+relTime+"\treltime="+movie.duration());
movie.setTime(relTime);
canvas.scale(3.50f, 3.50f);
movie.draw(canvas,20,20);
this.invalidate();
}
}

的Manifest.xml

Manifest.xml

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

    <application
        android:allowBackup="true"
        android:icon="@drawable/ic_launcher"
        android:label="@string/app_name"
        android:theme="@style/AppTheme" >       
        <activity
            android:name=".SplashScreen"
            android:label="@string/app_name"
            android:screenOrientation="portrait"
            android:theme="@android:style/Theme.Black.NoTitleBar" >
            <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/app_name" >
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />

                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>

         <activity
            android:name=".SecondActivity" 
            android:label="@string/app_name"/>
    </application>

</manifest>

logcat的误差

Logcat error

07-24 17:04:36.332: E/AndroidRuntime(580): FATAL EXCEPTION: main

07-24 17:04:36.332: E/AndroidRuntime(580): android.content.ActivityNotFoundException: Unable to find explicit activity class 

{.MYGIFView}; have you declared this activity in your AndroidManifest.xml?
07-24 17:04:36.332: E/AndroidRuntime(580):  at android.app.Instrumentation.checkStartActivityResult(Instrumentation.java:1508)
07-24 17:04:36.332: E/AndroidRuntime(580):  at android.app.Instrumentation.execStartActivity(Instrumentation.java:1384)
07-24 17:04:36.332: E/AndroidRuntime(580):  at android.app.Activity.startActivityForResult(Activity.java:3190)
07-24 17:04:36.332: E/AndroidRuntime(580):  at android.app.Activity.startActivity(Activity.java:3297)
07-24 17:04:36.332: E/AndroidRuntime(580):  at com.$1.run(SplashScreen.java:29)
07-24 17:04:36.332: E/AndroidRuntime(580):  at android.os.Handler.handleCallback(Handler.java:605)
07-24 17:04:36.332: E/AndroidRuntime(580):  at android.os.Handler.dispatchMessage(Handler.java:92)
07-24 17:04:36.332: E/AndroidRuntime(580):  at android.os.Looper.loop(Looper.java:137)
07-24 17:04:36.332: E/AndroidRuntime(580):  at android.app.ActivityThread.main(ActivityThread.java:4340)
07-24 17:04:36.332: E/AndroidRuntime(580):  at java.lang.reflect.Method.invokeNative(Native Method)
07-24 17:04:36.332: E/AndroidRuntime(580):  at java.lang.reflect.Method.invoke(Method.java:511)
07-24 17:04:36.332: E/AndroidRuntime(580):  at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:784)
07-24 17:04:36.332: E/AndroidRuntime(580):  at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:551)
07-24 17:04:36.332: E/AndroidRuntime(580):  at dalvik.system.NativeStart.main(Native Method)

在此先感谢..

Thanks in advance..

推荐答案

您code开始一个新的活动与MYGIFView类。
这似乎应该是一个活动,而不是一个视图。

Your code is starting a new "activity" with the MYGIFView class. It seem that it should be an activity, not a View.

想想只是需要有

setContentView(new MYGIFView(this));

在SplashActivity的OnCreate,处理程序声明之前。
并删除它在MainActivity的OnCreate(它似乎是一个错误在这里)。

In the onCreate of the SplashActivity, before the handler declaration. and remove it in the onCreate of the MainActivity (seem it's a mistake here).

,然后替换 MyGIFView.class MainActivity.class 在后延迟处理程序:

And then replace MyGIFView.class with MainActivity.class in the post delayed Handler :

Intent i = new Intent(SplashScreen.this, MainActivity.class);

和还需要删除清单的 LAUNCHER 参数为主要活动:

And also need to remove the LAUNCHER and MAIN param of the manifest for the main activity:

<intent-filter>
    <action android:name="android.intent.action.MAIN" />

    <category android:name="android.intent.category.LAUNCHER" />
</intent-filter>

编辑:erata SecondActivity - > MainActivity

Edited : erata SecondActivity -> MainActivity

这篇关于如何启动画面名为.gif动画文件连接?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆