我试图在3秒钟后自动显示另一个活动,但我在第二个屏幕上出现了一个奇怪的闪烁。 这就是我得到的: https://i.gyazo.com/bfd2c003b2bdd3a639a6db5f658da062.gif
我的代码:
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
ImageView image = (ImageView) findViewById(R.id.imageView1);
TextView text = (TextView) findViewById(R.id.text2);
Typeface cfont = Typeface.createFromAsset(getAssets(), "fonts/KeeponTruckin.ttf");
text.setTypeface(cfont);
final Handler handler = new Handler();
handler.postDelayed(new Runnable() {
public void run() {
// TODO: Your application init goes here.
Intent intent = new Intent(MainActivity.this, SecondActivity.class);
MainActivity.this.startActivity(intent);
MainActivity.this.finish();
}
}, 3000);
}
感谢您的帮助。
答案 0 :(得分:0)
我不知道为什么,maby模拟器android制作它。 您可以为plash_screen活动设置转换(例如:淡出)以获得最佳UX。 将folow代码插入代码
enum Direction:String {
case N = "n"
case NE = "ne"
case E = "e"
case SE = "se"
case S = "s"
case SW = "sw"
case W = "w"
case NW = "nw"
}
enum Action: String {
case Idle = "droid"
case Move = "droid_move"
}
func spriteFramesDroid(direction:Direction, action:Action) -> String {
return "\(action.rawValue)_\(direction.rawValue)"
}
fade_in.xml(推送到Intent intent = new Intent(MainActivity.this, SecondActivity.class);
MainActivity.this.startActivity(intent);
overridePendingTransition(R.anim.fade_in, R.anim.fade_out);
文件夹)
anim
fade_out.xml
<?xml version="1.0" encoding="utf-8"?>
<?xml version="1.0" encoding="utf-8"?>
<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="500" />
答案 1 :(得分:0)
如果您不想要进行动画转换,请将您的意图更改为:
Intent intent = new Intent(MainActivity.this, SecondActivity.class);
intent.setFlags(Intent.FLAG_ACTIVITY_NO_ANIMATION);
MainActivity.this.startActivity(intent);
MainActivity.this.finish();
如果您想要淡入/淡出效果,请在开始活动前调用以下内容:
overridePendingTransition(android.R.anim.fade_in, android.R.anim.fade_out);