如何在启动画面中加载3点动画

Sac*_*chi 3 android splash-screen

嗨,我正在尝试制作我的第一个Android应用程序,我做了一个闪屏.但是,我尝试添加加载请在底部等待,每2秒增加一次.我不确定如何实现它,因为屏幕因为这个文本崩溃了.

   final TextView loadingText = (TextView)findViewById(R.id.loading_text);

    Thread splashTimer = new Thread(){
        public void run(){
            try{
                int splashTime = 0;
                while(splashTime < 6000){

                    sleep(100);

                        if(splashTime < 2000){
                            loadingText.setText("Loading.");
                        }
                        else if(splashTime >= 2000 && splashTime < 4000 ){
                            loadingText.setText("Loading..");
                        }else if (splashTime >= 4000){
                            loadingText.setText("Loading...");  
                        }
                        splashTime = splashTime + 100;

                }
                Intent intent = new Intent(MainActivity.this,myMainScreen.class);
                startActivity(intent);
            }catch(InterruptedException e){
                e.printStackTrace();
            }

            finally{
                finish();
            }
        }
    };
    splashTimer.start();    
}  
Run Code Online (Sandbox Code Playgroud)

这是我的logcat

06-12 01:36:33.646: D/HyLog(29533): I : /data/font/config/sfconfig.dat, No such file or directory (2)
06-12 01:36:33.646: D/HyLog(29533): I : /data/font/config/dfactpre.dat, No such file or directory (2)
06-12 01:36:33.646: D/HyLog(29533): I : /data/font/config/sfconfig.dat, No such file or directory (2)
06-12 01:36:33.986: I/Adreno-EGL(29533): <qeglDrvAPI_eglInitialize:385>: EGL 1.4 QUALCOMM build:  ()
06-12 01:36:33.986: I/Adreno-EGL(29533): OpenGL ES Shader Compiler Version: E031.24.00.02
06-12 01:36:33.986: I/Adreno-EGL(29533): Build Date: 01/20/14 Mon
06-12 01:36:33.986: I/Adreno-EGL(29533): Local Branch: PMH2-KK_3.5-RB1-AU61-554722-586267-set2
06-12 01:36:33.986: I/Adreno-EGL(29533): Remote Branch: 
06-12 01:36:33.986: I/Adreno-EGL(29533): Local Patches: 
06-12 01:36:33.986: I/Adreno-EGL(29533): Reconstruct Branch: 
06-12 01:36:34.026: D/OpenGLRenderer(29533): Enabling debug mode 0
06-12 01:36:34.096: I/ActivityManager(29533): Timeline: Activity_idle id: android.os.BinderProxy@42b1e788 time:14063098
06-12 01:36:34.336: W/dalvikvm(29533): threadid=11: thread exiting with uncaught exception (group=0x41ae6e48)
06-12 01:36:34.336: E/AndroidRuntime(29533): FATAL EXCEPTION: Thread-2388
06-12 01:36:34.336: E/AndroidRuntime(29533): Process: com.sachinda.myfirstapp, PID: 29533
06-12 01:36:34.336: E/AndroidRuntime(29533): android.view.ViewRootImpl$CalledFromWrongThreadException: Only the original thread that created a view hierarchy can touch its views.
06-12 01:36:34.336: E/AndroidRuntime(29533):    at android.view.ViewRootImpl.checkThread(ViewRootImpl.java:6347)
06-12 01:36:34.336: E/AndroidRuntime(29533):    at android.view.ViewRootImpl.requestLayout(ViewRootImpl.java:871)
06-12 01:36:34.336: E/AndroidRuntime(29533):    at android.view.View.requestLayout(View.java:16472)
06-12 01:36:34.336: E/AndroidRuntime(29533):    at android.view.View.requestLayout(View.java:16472)
06-12 01:36:34.336: E/AndroidRuntime(29533):    at android.view.View.requestLayout(View.java:16472)
06-12 01:36:34.336: E/AndroidRuntime(29533):    at android.view.View.requestLayout(View.java:16472)
06-12 01:36:34.336: E/AndroidRuntime(29533):    at android.widget.RelativeLayout.requestLayout(RelativeLayout.java:352)
06-12 01:36:34.336: E/AndroidRuntime(29533):    at android.view.View.requestLayout(View.java:16472)
06-12 01:36:34.336: E/AndroidRuntime(29533):    at android.widget.TextView.checkForRelayout(TextView.java:6817)
06-12 01:36:34.336: E/AndroidRuntime(29533):    at android.widget.TextView.setText(TextView.java:3947)
06-12 01:36:34.336: E/AndroidRuntime(29533):    at android.widget.TextView.setText(TextView.java:3805)
06-12 01:36:34.336: E/AndroidRuntime(29533):    at android.widget.TextView.setText(TextView.java:3780)
06-12 01:36:34.336: E/AndroidRuntime(29533):    at com.sachinda.myfirstapp.MainActivity$1.run(MainActivity.java:45)
06-12 01:36:36.316: I/Process(29533): Sending signal. PID: 29533 SIG: 9
Run Code Online (Sandbox Code Playgroud)

小智 8

它崩溃是因为你在非UI线程添加方法上修改ui组件

private void setText(final CharSequence text) {
    runOnUiThread(new Runnable() {
        @Override
        public void run() {
            ((TextView) findViewById(R.id.loading_text)).setText(text);
        }
    });
}
Run Code Online (Sandbox Code Playgroud)

并修改您的代码以使用该方法

while(splashTime < 6000){

     sleep(100);

     if(splashTime < 2000){
         setText("Loading.");
     }
     else if(splashTime >= 2000 && splashTime < 4000 ){
         setText("Loading..");
     }else if (splashTime >= 4000){
         setText("Loading...");
     }
          splashTime = splashTime + 100;

 }
Run Code Online (Sandbox Code Playgroud)