简体   繁体   English

启动画面淡入淡出动画问题

[英]Splash Screen Fade Animation issue

I done a fade animation with three images displayed in splash screen.I got an output successfully. 我完成了一个fade动画,在初始屏幕中显示了three images

But I got a two issue : 但是我有two issue

  1. Time Loading: 时间加载:

    • It tooks more time to load a splash screen.It needs to enter into the application as soon as possible. 加载初始屏幕花了更多时间,需要尽快进入应用程序。
  2. App doesn't Close: 应用无法关闭:

    • After entered into an Application.I am trying to close these app with the help of Back Button in emulator.But It never closes an 进入应用程序后,我试图在模拟器中使用后退按钮关闭这些应用程序,但是它永远不会关闭
      application. 应用。

    • It stays in an application itself.In log cats,I seen the loop 1,2 and 3 continues again and again.I can't able to close my app. 它停留在应用程序本身中。在日志猫中,我看到1,2和3循环一次又一次地继续。我无法关闭我的应用程序。

    • If I am press the Home Button,It displays a home screen but again enter into an application automatically. 如果按主屏幕按钮,它将显示主屏幕,但再次自动进入应用程序。

LogCat: LogCat:

I am not getting any logcat error.But you can see that logcat readings always running.It never gets stop.The loop 1,2 and 3 continuously reading in logcat.For these it never closes an application.Then If I am press the home button,home screen would be displayed.But sometimes it automatically enter into these application. 我没有收到任何logcat错误。但是您可以看到logcat读数始终在运行。它永远不会停止。循环1,2和3连续读取logcat。对于这些来说,它永远不会关闭应用程序。按钮,将显示主屏幕。但是有时它会自动进入这些应用程序。

06-25 05:46:27.654: V/test(1842): 1
06-25 05:46:27.684: V/test(1842): 2
06-25 05:46:31.764: V/test(1842): 1
06-25 05:46:35.654: V/test(1842): 2
06-25 05:46:35.684: V/test(1842): 3
06-25 05:46:39.764: V/test(1842): 2
06-25 05:46:43.654: V/test(1842): 3
06-25 05:46:43.684: V/test(1842): 1
06-25 05:46:44.914: I/Choreographer(1842): Skipped 36 frames!  The application may be doing too much work on its main thread.
06-25 05:46:46.524: I/ImageCache(1842): Memory cache created (size = 12288)
06-25 05:46:46.534: V/test1(1842): testhere
06-25 05:46:46.534: V/3333333(1842): 3333333
06-25 05:46:47.334: V/####(1842): TFH BANNER1
06-25 05:46:47.434: V/test2(1842): testhere
06-25 05:46:47.434: V/test3(1842): testhere
06-25 05:46:47.434: V/####(1842): TFH BANNER2
06-25 05:46:47.444: V/####(1842): TFH BANNER3
06-25 05:46:47.494: V/####(1842): TFH BANNER4
06-25 05:46:47.674: V/####(1842): TFH BANNER1
06-25 05:46:47.674: V/test2(1842): testhere
06-25 05:46:47.684: V/test3(1842): testhere
06-25 05:46:47.684: I/ImageWorker(1842): cancelPotentialWork - cancelled work for http://tfhapp.fathershouse.in/banner-gallery/tfh-banner1-large-1.jpg
06-25 05:46:47.684: V/####(1842): TFH BANNER2
06-25 05:46:47.684: V/####(1842): TFH BANNER3
06-25 05:46:47.684: V/####(1842): TFH BANNER4
06-25 05:46:47.764: V/test(1842): 3
06-25 05:46:47.864: V/APIServiceHandler(1842): API CALLhttp://tfhapp.fathershouse.in/api/video.php
06-25 05:46:47.864: I/ImageWorker(1842): doInBackground - starting work
06-25 05:46:48.004: V/####(1842): TFH BANNER1
06-25 05:46:48.004: V/test2(1842): testhere
06-25 05:46:48.014: V/test3(1842): testhere
06-25 05:46:48.014: V/####(1842): TFH BANNER2
06-25 05:46:48.024: V/####(1842): TFH BANNER3
06-25 05:46:48.024: V/####(1842): TFH BANNER4
06-25 05:46:48.034: V/####(1842): TFH BANNER1
06-25 05:46:48.044: V/test2(1842): testhere
06-25 05:46:48.044: V/test3(1842): testhere
06-25 05:46:48.064: V/####(1842): TFH BANNER2
06-25 05:46:48.144: V/####(1842): TFH BANNER3
06-25 05:46:48.274: I/Choreographer(1842): Skipped 1086 frames!  The application may be doing too much work on its main thread.
06-25 05:46:48.674: I/ImageCache(1842): Disk cache initialized
06-25 05:46:48.854: I/Choreographer(1842): Skipped 205 frames!  The application may be doing too much work on its main thread.
06-25 05:46:49.164: V/####(1842): TFH BANNER1
06-25 05:46:49.254: V/test2(1842): testhere
06-25 05:46:49.254: V/test3(1842): testhere
06-25 05:46:49.264: V/####(1842): TFH BANNER2
06-25 05:46:49.324: V/####(1842): TFH BANNER3
06-25 05:46:49.324: V/####(1842): TFH BANNER4
06-25 05:46:49.374: V/####(1842): TFH BANNER1
06-25 05:46:49.434: V/test2(1842): testhere
06-25 05:46:49.434: V/test3(1842): testhere
06-25 05:46:49.434: I/ImageWorker(1842): cancelPotentialWork - cancelled work for http://tfhapp.fathershouse.in/banner-gallery/tfh-banner1-large-1.jpg

Below I posted my entire core related to SplashActivity. 下面,我发布了与SplashActivity相关的整个核心。

SplashActivity.java: SplashActivity.java:

public class SplashActivity extends Activity {

    public int currentimageindex = 0;
    Timer timer;
    TimerTask task;
    ImageView slidingimage;
    int count = 0;
    private int[] IMAGE_IDS = { R.drawable.spl1, R.drawable.spl2,
            R.drawable.spl3 };

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.layout_splash);
        final Handler mHandler = new Handler();

        // Create runnable for posting
        final Runnable mUpdateResults = new Runnable() {
            public void run() {

                AnimateandSlideShow();

            }
        };

        int delay = 1000; // delay for 1 sec.

        int period = 8000; // repeat every 4 sec.

        Timer timer = new Timer();

        timer.scheduleAtFixedRate(new TimerTask() {

            public void run() {

                mHandler.post(mUpdateResults);
                count = count + 1;

                Log.v("test", count + "");
                if (count >3) {

                    Intent i=new Intent(SplashActivity.this,HomeActivity.class);
                    startActivity(i);
                    count=0;  
                }
            }
        }, delay, period);

    }

    //
    // public void onClick(View v) {
    //
    // finish();
    // android.os.Process.killProcess(android.os.Process.myPid());
    // }

    /**
     * Helper method to start the animation on the splash screen
     */
    private void AnimateandSlideShow() {

        slidingimage = (ImageView) findViewById(R.id.ImageView3_Left);
        slidingimage.setImageResource(IMAGE_IDS[currentimageindex
                % IMAGE_IDS.length]);

        currentimageindex++;

        Animation rotateimage = AnimationUtils.loadAnimation(this,
                R.anim.custom_anim);

        slidingimage.startAnimation(rotateimage);

        // Log.v("test","animation slide");

    }

}  

layout_splash.xml: layout_splash.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" >

    <ImageView
        android:id="@+id/ImageView3_Left"
          android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_gravity="center_vertical|center_horizontal" />


</LinearLayout>  

custom_anim.xml: custom_anim.xml:

<?xml version="1.0" encoding="utf-8" ?>
<set
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:shareInterpolator="false">
    <rotate
        android:fromDegrees="0"
        android:toDegrees="360"
        android:pivotX="50%"
        android:pivotY="50%"
        android:duration="2000" />
    <alpha
        android:fromAlpha="0.0"
        android:toAlpha="1.0"
        android:duration="2000">
    </alpha>
    <scale
        android:pivotX="50%"
        android:pivotY="50%"
        android:fromXScale=".1"
        android:fromYScale=".1"
        android:toXScale="1.0"
        android:toYScale="1.0"
        android:duration="2000" />

</set>

fade_in.xml: fade_in.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">
    </alpha>
</set>

fade_in2.xml: 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>

I doesn't know how to solve these problem.Anybody can help me if you know how to solve these.Thank You. 我不知道如何解决这些问题。如果您知道如何解决这些问题,任何人都可以帮助我。谢谢。

Please refer this code segments for solution of your problem.. 请参考此代码段以解决您的问题。

package com.example.splashanimation;

import java.util.Timer;
import java.util.TimerTask;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.os.Handler;
import android.util.Log;
import android.view.animation.Animation;
import android.view.animation.AnimationUtils;
import android.widget.ImageView;

public class MainActivity extends Activity {

    public int currentimageindex = 0;
    Timer timer;
    TimerTask task;
    ImageView slidingimage;
    int count = 0;
    private int[] IMAGE_IDS = { R.drawable.img1, R.drawable.img2, R.drawable.img3 };

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        final Handler mHandler = new Handler();

        // Create runnable for posting
        final Runnable mUpdateResults = new Runnable() {
            public void run() {

                AnimateandSlideShow();

            }
        };

        int delay = 500; // delay for 1 sec.

        int period = 4000; // repeat every 4 sec.

        final Timer timer = new Timer();

        timer.scheduleAtFixedRate(new TimerTask() {

            public void run() {

                mHandler.post(mUpdateResults);
                count = count + 1;

                Log.v("test", count + "");
                if (count > 3) {
                    finish();
                    Intent i = new Intent(MainActivity.this, HomeActivity.class);
                    startActivity(i);
                    count = 0;
                    timer.cancel();
                }
            }
        }, 0, period);

    }

    /**
     * Helper method to start the animation on the splash screen
     */
    private void AnimateandSlideShow() {

        slidingimage = (ImageView) findViewById(R.id.ImageView3_Left);
        slidingimage.setImageResource(IMAGE_IDS[currentimageindex % IMAGE_IDS.length]);

        currentimageindex++;

        Animation rotateimage = AnimationUtils.loadAnimation(this, R.anim.custom_anim);

        slidingimage.startAnimation(rotateimage);

    }

}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM