2014-04-15 204 views
0

我在机器人编程新的,在这里我试图创造一些闪屏有3倍不同的图像显示了使用RunOnUIThread了一个又一个,这里的代码飞溅装载跳过过渡动画

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); 
} 

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> 

exe文件后切割它在Android模拟器,我得到了logcat消息说,它跳过了42帧,因为应用程序做了太多的工作,它的主线程和过渡动画不工作,因为我的意图..我做了错误的线程?请指导我解释一下。

回答

0

我想通过各种可能的方式后出来的东西..和帧跳过发生,因为我不完全停止线程(我猜?纠正我,如果这个错误),所以我会加返回;停止线程这样的:

... 
if(loading_count >= 170){ 
    StartMainMenu(); 
    return; 
} 
... 

现在的过渡动画都没有跳过任何帧..对不起,问愚蠢的问题,并张贴愚蠢的答案工作。