Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/178.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
如何在android中实现闪屏_Android - Fatal编程技术网

如何在android中实现闪屏

如何在android中实现闪屏,android,Android,我有一个显示项目列表的应用程序。在开始主要活动之前,我需要显示淡出图像。 我试过类似的东西 在我开始的主要活动的onCreate方法中 一个像这样的动画活动 Intent animationIntent=new Intent(this,AnimationActivity.class); startActivityForResult(AnimationIntent); 在AnimationActivity.class的onCreate方法中 super.onCreate(savedInstanc

我有一个显示项目列表的应用程序。在开始主要活动之前,我需要显示淡出图像。 我试过类似的东西 在我开始的主要活动的onCreate方法中 一个像这样的动画活动

Intent animationIntent=new Intent(this,AnimationActivity.class);
startActivityForResult(AnimationIntent);
在AnimationActivity.class的onCreate方法中

super.onCreate(savedInstanceState);
    setContentView(R.layout.main);
    ImageView introanim = (ImageView) findViewById(R.id.imgView);
    AnimationSet StoryAnimation = (AnimationSet)AnimationUtils.
loadAnimation(this, R.anim.alphanim);
StoryAnimation.setAnimationListener(new AnimationListener() {

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

        }

        @Override
        public void onAnimationRepeat(Animation animation) {
                AnimationSubActivity.this.finish();

        }

        @Override
        public void onAnimationEnd(Animation animation) {
            AnimationSubActivity.this.finish();
        }
    });

    introanim.clearAnimation();
    introanim.startAnimation(StoryAnimation);
我的main.xml是

<?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"
>
<ImageView  
android:id="@+id/imgView"
android:layout_width="fill_parent" 
android:layout_height="fill_parent" 
android:src="@drawable/icon"
/>
</LinearLayout>

这种方法的问题是,它显示一个信息,但imageview会在屏幕上显示一段时间,并且主要活动带有幻灯片过渡效果

但我希望我的形象淡出,我的活动应该淡入


任何帮助都将不胜感激。提前感谢

基本上,你要找的是一个闪屏,它会显示你的图像,然后消失。主活动的屏幕随后淡入。因此,您可以为初始屏幕创建一个活动,然后为您可能要调用的主活动创建另一个活动。这将是您的启动屏幕活动

public class SplashScreen extends Activity {
private static final int SPLASH_DISPLAY_TIME = 4000; // splash screen delay time

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.splash);

    new Handler().postDelayed(new Runnable() {
        public void run() {

            Intent intent = new Intent();
            intent.setClass(Splash.this, NextActivity.class);

            Splash.this.startActivity(intent);
            Splash.this.finish();

            // transition from splash to main menu
            overridePendingTransition(R.animate.activityfadein,
                    R.animate.splashfadeout);

        }
    }, SPLASH_DISPLAY_TIME);
}
NextActivity是任何你想淡入并取代它的活动。对于动画,您需要在资源中名为animate的文件夹中创建两个xml文件。 这是splashfadeout.xml文件

<alpha xmlns:android="http://schemas.android.com/apk/res/android"
android:interpolator="@android:anim/decelerate_interpolator"
android:zAdjustment="top" android:fromAlpha="1.0" android:toAlpha="0.0"
android:duration="4000" />

这将是activityfadein.xml文件

<alpha xmlns:android="http://schemas.android.com/apk/res/android"
android:interpolator="@android:anim/accelerate_interpolator"
android:fromAlpha="0.0" android:toAlpha="1.0" android:duration="2000" />

这些文件基本上会使你的活动淡入淡出。

一个“闪屏”,就像@Manish Burman建议的那样,不是真正的闪屏。它实际上只是一个“全屏商业广告”,没有用户愿意花时间去看它。它没有任何用途,除了在那里,这意味着它不会掩盖长加载时间或该区域中的某些东西,就像真正的启动屏幕应该掩盖的那样

如果你要显示一个启动屏幕,应该是因为你有一个需要花费相当长时间才能加载的初始活动-然后启动屏幕可以是合理的,向用户显示东西正在加载,或者让他相信应用程序没有“死亡”


查看关于如何创建真正的启动屏幕的指南。

@user609765如果答案解决了您的问题,您应该接受它。为什么您要使用处理程序来启动活动,而不仅仅是在OnCreate中启动活动?感谢这一惊人的提示。请注意,文件夹应命名为“anim”,而不是“animate”。干杯!这段代码不是在其他线程(主线程除外)中启动其他活动吗?我很困惑。请澄清。无效的资源目录名称。