Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/310.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

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/220.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
Java 飞溅加载跳过了过渡动画_Java_Android_Transition - Fatal编程技术网

Java 飞溅加载跳过了过渡动画

Java 飞溅加载跳过了过渡动画,java,android,transition,Java,Android,Transition,我是android编程新手,在这里我尝试创建一些启动屏幕,使用RunOnUIThread一个接一个地显示3个不同的图像,下面是代码 Splash.java public class Splash extends Activity { int loading_count; int imgShowed = 1; ImageView img1, img2; ImageSwitcher imgSwitcher; @Override protected void onCreate(Bundle sav

我是android编程新手,在这里我尝试创建一些启动屏幕,使用RunOnUIThread一个接一个地显示3个不同的图像,下面是代码

Splash.java

public class Splash extends Activity {

int loading_count;
int imgShowed = 1;
ImageView img1, img2;
ImageSwitcher imgSwitcher;

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

    img1 = (ImageView)findViewById(R.id.img01);
    img2 = (ImageView)findViewById(R.id.img02);
    imgSwitcher = (ImageSwitcher)findViewById(R.id.splash_switcher);

    LoadingThread();
}

private void LoadingThread(){
    Thread loading = new Thread(){
        @Override
        public void run(){
            try{
            //=================================//
            //   Looping for splash loading    //
            //=================================//
                while(loading_count < 170){
                    sleep(50);
                    runOnUiThread(new Runnable(){
                        @Override
                        public void run() {
                            if(loading_count >=20){
                                if(imgShowed == 1){
                                    imgSwitcher.showNext();
                                    imgShowed = 2;
                                }
                            }if(loading_count >= 70){
                                if(imgShowed == 2){
                                    img1.setImageResource(R.drawable.two);
                                    imgSwitcher.showNext();
                                    imgShowed = 3;
                                }
                            }if(loading_count >= 120){
                                if(imgShowed == 3){
                                    img2.setImageResource(R.drawable.three);
                                    imgSwitcher.showNext();
                                    imgShowed = 4;
                                }
                            }
                            loading_count += 1;
                        }
                    });
                }
            }catch(InterruptedException e){
                e.printStackTrace();
            }finally{
                StartMainMenu();
            }
        }
    };
    loading.start();
}

private void StartMainMenu(){
    Intent mainmenu = new Intent(this, MainMenu.class);
    finish();
    startActivity(mainmenu);
    overridePendingTransition(R.anim.fade_in, R.anim.fade_out);
}
公共类启动扩展活动{
整数装载计数;
int imgShowed=1;
ImageView img1、img2;
图像开关;
@凌驾
创建时受保护的void(Bundle savedInstanceState){
super.onCreate(savedInstanceState);
setContentView(R.layout.splash);
img1=(ImageView)findViewById(R.id.img01);
img2=(ImageView)findViewById(R.id.img02);
imgSwitcher=(图像切换器)findViewById(R.id.splash_切换器);
加载线程();
}
私有void加载线程(){
线程加载=新线程(){
@凌驾
公开募捐{
试一试{
//=================================//
//飞溅加载循环//
//=================================//
同时(装载计数<170){
睡眠(50);
runOnUiThread(新的Runnable(){
@凌驾
公开募捐{
如果(加载计数>=20){
如果(imgShowed==1){
imgSwitcher.showNext();
imgShowed=2;
}
}如果(加载计数>=70){
如果(imgShowed==2){
img1.setImageResource(R.drawable.two);
imgSwitcher.showNext();
imgShowed=3;
}
}如果(加载计数>=120){
如果(imgShowed==3){
img2.setImageResource(R.drawable.three);
imgSwitcher.showNext();
imgShowed=4;
}
}
装载计数+=1;
}
});
}
}捕捉(中断异常e){
e、 printStackTrace();
}最后{
StartMainMenu();
}
}
};
加载.start();
}
私有void StartMainMenu(){
Intent mainmenu=新的Intent(这是mainmenu.class);
完成();
startActivity(主菜单);
覆盖转换(R.anim.fade\u in,R.anim.fade\u out);
}
Layout.xml

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

    <ImageSwitcher 
        android:id="@+id/splash_switcher"
        android:layout_centerInParent="true"
        android:layout_width="200dp"
        android:layout_height="200dp"
        android:background="#00000000"
        android:inAnimation="@anim/fade_in"
        android:outAnimation="@anim/fade_out"
        >

        <ImageView 
            android:id="@+id/img01"
            android:layout_height="200dp"
            android:layout_width="200dp"
            android:scaleType="fitXY"
            android:background="#000000"
            android:contentDescription="@string/app_name"
            />

        <ImageView 
            android:id="@+id/img02"
            android:layout_height="200dp"
            android:layout_width="200dp"
            android:scaleType="fitXY"
            android:background="@drawable/one"
            android:contentDescription="@string/app_name"
            />

    </ImageSwitcher>

</RelativeLayout>


在android emulator上执行后,我在logcat中收到消息说它跳过了42帧,因为应用程序在其主线程上做了太多的工作,而转换动画并没有按照我的预期工作。我在线程中做错了什么吗?请给我一个解释来指导我。我在尝试过之后发现了一些问题y可能的方式..跳过帧是因为我没有完全停止线程(我猜?如果这个错误请纠正我),因此我将添加return;以如下方式停止线程:

...
if(loading_count >= 170){
    StartMainMenu();
    return;
}
...
现在过渡动画在不跳过任何帧的情况下工作..很抱歉问了一个愚蠢的问题并发布了愚蠢的答案