SplashActivity
package com.example.huayuan;
import android.animation.ObjectAnimator;
import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.os.Handler;
import android.support.v7.app.AppCompatActivity;
import android.view.View;
import android.widget.Button;
public class SplashActivity extends AppCompatActivity implements View.OnClickListener {
Handler handler;
private Button mBtn;
int time = 3;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.welocom);
initView();
handler = new Handler();
}
private void initView() {
mBtn = (Button) findViewById(R.id.btn);
mBtn.setOnClickListener(this);
}
@Override
public void onClick(View v) {
switch (v.getId()) {
case R.id.btn:
ObjectAnimator animator = ObjectAnimator.ofFloat(v, "translationY", 0f, 300f);
animator.setDuration(5000);
animator.start();
handler.postDelayed(new Runnable() {
@Override
public void run() {
time--;
if (time == 1) {
Intent intent = new Intent(SplashActivity.this, MainActivity.class);
startActivity(intent);
}
handler.postDelayed(this,3000);
}
}, 200);
break;
default:
break;
}
}
}
welocom.xml
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent">
<Button
android:layout_gravity="center_horizontal"
android:id="@+id/btn"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="跳转"
android:layout_alignParentTop="true"
android:layout_centerHorizontal="true" />
</RelativeLayout>
AndroidManifest.xml
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.huayuan">
<application
android:allowBackup="true"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:roundIcon="@mipmap/ic_launcher_round"
android:supportsRtl="true"
android:theme="@style/AppTheme">
<activity android:name=".SplashActivity">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity android:name=".MainActivity"></activity>
</application>
</manifest>