我想创建一个启动画面,我想显示一些视图(已经使它们在XML中不可见),在最后一个视图通过Java代码变为可见后,我想打开另一个活动,我知道我应该创建处理程序和可运行对象这样做,但是我不知道该怎么做! 有人可以告诉我如何使用代码吗?这是我到目前为止所做的。
public class SplashActivity extends AppCompatActivity {
private static final int SPLASH_TIME_OUT = 3600;
private static final int VIEW_COUNT = 4;
private TextView welcome_tv1, welcome_tv2, welcome_tv3;
private ImageView logo;
private Typeface typeface;
private Handler handler = new Handler();
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
WindowManager.LayoutParams.FLAG_FULLSCREEN);
setContentView(R.layout.activity_splash);
init();
setAnimations();
handler.postDelayed(new Runnable() {
@Override
public void run() {
startActivity(new Intent(SplashActivity.this, MainActivity.class));
finish();
}
}, SPLASH_TIME_OUT);
}
private void setAnimations() {
YoYo.with(Techniques.FadeInDown)
.duration(2500)
.repeat(0)
.playOn(logo);
logo.setVisibility(View.VISIBLE);
YoYo.with(Techniques.FadeInDown)
.repeat(0)
.delay(400)
.duration(1000)
.playOn(welcome_tv1);
welcome_tv1.setVisibility(View.VISIBLE);
YoYo.with(Techniques.FadeInDown)
.repeat(0)
.delay(1400)
.duration(1000)
.playOn(welcome_tv2);
welcome_tv2.setVisibility(View.VISIBLE);
YoYo.with(Techniques.FadeInDown)
.repeat(0)
.delay(2800)
.duration(800)
.playOn(welcome_tv3);
welcome_tv3.setVisibility(View.VISIBLE);
}
private void init() {
welcome_tv1 = findViewById(R.id.welcome_tv_one);
welcome_tv2 = findViewById(R.id.welcome_tv_two);
welcome_tv3 = findViewById(R.id.welcome_tv_three);
typeface = Typeface.createFromAsset(getApplicationContext().getAssets(),
"Fonts/myFont.ttf");
logo = findViewById(R.id.logo);
setTextViews();
}
private void setTextViews() {
welcome_tv1.setText(getResources().getString(R.string.welcome_tv_txt));
welcome_tv2.setText(getResources().getString(R.string.welcome_tv2_txt));
welcome_tv3.setText(getResources().getString(R.string.welcome_tv3_txt));
welcome_tv1.setTypeface(typeface);
welcome_tv2.setTypeface(typeface);
welcome_tv3.setTypeface(typeface);
}
答案 0 :(得分:1)