1. 程式人生 > >類似淘寶,京東,火山小視訊的倒計時跳轉頁面

類似淘寶,京東,火山小視訊的倒計時跳轉頁面

activity_main

<?xml version="1.0" encoding="utf-8"?>
<android.support.constraint.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
android:layout_height="match_parent" tools:context="com.bawei.huoshan_lss.MainActivity">
<ImageView android:id="@+id/welcom" android:layout_width="match_parent" android:layout_height="match_parent" android:src="@mipmap/sy" /> </android.support.constraint.ConstraintLayout
>

MainActivity

public class MainActivity extends AppCompatActivity {
int time=3;
Handler handler;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        handler = new Handler();
        handler.postDelayed(new
Runnable() { @Override public void run() { time--; if(time==0){ /*新建一個要跳轉到的頁面*/ Intent intent = new Intent(MainActivity.this,Main2Activity.class); startActivity(intent); return; } handler.postDelayed(this,1000); } },1000); } }