3秒跳转
/** * 三秒跳转 */ public class MainActivity extends AppCompatActivity { ImageView splashImage; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); splashImage = (ImageView) findViewById(R.id.iv_splan); setAlphaAnimation(); } private void setAlphaAnimation() { AlphaAnimation alpha = new AlphaAnimation(0,1); alpha.setDuration(3000); alpha.setFillAfter(true); alpha.setAnimationListener(new Animation.AnimationListener() { @Override public void onAnimationStart(Animation animation) { } @Override public void onAnimationEnd(Animation animation) { Intent intent = new Intent(MainActivity.this,LoginActivity.class); startActivity(intent); finish(); } @Override public void onAnimationRepeat(Animation animation) { } }); splashImage.setAnimation(alpha); } }
<?xml version="1.0" encoding="utf-8"?> <RelativeLayout 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=".a1login.MainActivity"> <ImageView android:layout_centerInParent="true" android:layout_width="wrap_content" android:layout_height="wrap_content" android:id="@+id/iv_splan" android:src="@drawable/logo" /> </RelativeLayout>