一、xml
<ImageView
android:id="@+id/imageView"
android:scaleType="fitXY"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_weight="1"
app:srcCompat="@mipmap/ic_lunager" />
<TextView
android:id="@+id/textView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:layout_alignParentEnd="true"
android:layout_marginTop="26dp"
android:layout_marginEnd="26dp"
android:text="TextView" />
二、Activity
public class MainActivity extends AppCompatActivity {
public int time;
private ImageView imageView;
private TextView textView;
private Handler handler = new Handler(){
@Override
public void handleMessage(Message msg) {
super.handleMessage(msg);
if (time == 0){
startActivity(new Intent(MainActivity.this,Main2Activity.class));
finish();
return;
}
time--;
textView.setText("倒计时:"+time+"s");
handler.sendEmptyMessageDelayed(0,1000);
}
};
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
imageView = findViewById(R.id.imageView);
textView = findViewById(R.id.textView1);
time = 3;
textView.setText("倒计时:"+time+"s");
handler.sendEmptyMessageDelayed(0,1000);
}
}