0
我闪屏应用以13秒显示启动画面
/**
* Created by HumzaYunas on 05/01/2016.
*/
import android.app.Activity;
import android.content.Intent;
import android.graphics.PixelFormat;
import android.os.Bundle;
import android.view.Window;
import android.view.animation.Animation;
import android.view.animation.AnimationUtils;
import android.widget.ImageView;
import android.widget.LinearLayout;
public class splashscreen extends Activity {
public void onAttachedToWindow() {
super.onAttachedToWindow();
Window window = getWindow();
window.setFormat(PixelFormat.RGBA_8888);
}
/** Called when the activity is first created. */
Thread splashTread;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_splashscreen);
StartAnimations();
}
private void StartAnimations() {
Animation anim = AnimationUtils.loadAnimation(this, R.anim.alpha);
anim.reset();
LinearLayout l=(LinearLayout) findViewById(R.id.lin_lay);
l.clearAnimation();
l.startAnimation(anim);
anim = AnimationUtils.loadAnimation(this, R.anim.translate);
anim.reset();
ImageView iv = (ImageView) findViewById(R.id.splash);
iv.clearAnimation();
iv.startAnimation(anim);
splashTread = new Thread() {
@Override
public void run() {
try {
int waited = 0;
// Splash screen pause time
while (waited < 5000) {
sleep(100);
waited += 100;
}
Intent intent = new Intent(splashscreen.this,
MainActivity.class);
intent.setFlags(Intent.FLAG_ACTIVITY_NO_ANIMATION);
startActivity(intent);
splashscreen.this.finish();
} catch (InterruptedException e) {
// do nothing
} finally {
splashscreen.this.finish();
}
}
};
splashTread.start();
}
}
,这是需要很长时间,只要我想是这样:(......我只是好奇的是如何加载应用程序,如Facebook,当我们挖掘FB上的图标和应用程序加载速度极快和闪屏显示,但在我的应用我遇到了这个问题。任何帮助将不胜感激:) ..
这里
我androidmanifest<uses-permission android:name="android.permission.INTERNET" />
<application
android:allowBackup="true"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:supportsRtl="true"
android:theme="@style/Theme.AppCompat.Light.NoActionBar">
<activity android:name=".splashscreen"
android:label="@string/app_name">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity android:name=".MainActivity">
</activity>
<activity
android:name=".ShowPosts"
android:label="@string/posttitle"
android:parentActivityName=".MainActivity"/>
<activity android:name=".LiveScores" />
</application>
I只是做了我的闪屏作为主要的活动,因为我想加载我的应用程序快速使闪屏需要时间,那之后我mainactivity得到一些时间来工作和负载
其实我说的是我的应用程序开始延迟。即使显示启动画面也需要很长时间。这是问题:( –
我会建议你阅读如何正确地做到这一点(在我提供的链接中),你也不必用postDelay(new Runnable(),delayInMillis)来使用线程 –
我已经遵循了链接中的内容,但仍然在某种程度上与它相同,但实际上我是初学者,所以我不明白这些因素以及这些内容如何工作:) –