2.layout部分設兩個畫面供畫面轉換。
3.使用 Animation.AnimationListener 的介面,在 onAnimationEnd 裡當動畫結束後做intent的切換。
WelcomeActivity.java
package gae.melvin.com.app_welcomeview; import android.content.Context; import android.content.Intent; import android.support.v7.app.AppCompatActivity; import android.os.Bundle; import android.view.WindowManager; import android.view.animation.Animation; import android.view.animation.AnimationUtils; import android.widget.ImageView; public class WelcomeActivity extends AppCompatActivity implements Animation.AnimationListener{ private ImageView imageView; private Context context; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_welcome); context = this; //取消ActionBar getSupportActionBar().hide(); //取消狀態欄 this.getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN); imageView = (ImageView)findViewById(R.id.imageView); //imageView 設定動畫元件(透明度調整) Animation animation = AnimationUtils.loadAnimation(this, R.anim.welcome_anim); animation.setFillEnabled(true); animation.setFillAfter(true); animation.setAnimationListener(this); imageView.setAnimation(animation); } /*實作 Animation.AnimationListener 的三種方法*/ @Override public void onAnimationStart(Animation animation) {} @Override public void onAnimationEnd(Animation animation) { startActivity(new Intent(context,MainActivity.class)); finish(); } @Override public void onAnimationRepeat(Animation animation) {} }
MainActivity.java
package gae.melvin.com.app_welcomeview; import android.os.Bundle; import android.support.v7.app.AppCompatActivity; public class MainActivity extends AppCompatActivity { @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); setTitle("主畫面"); } }
4.呈現效果
太神拉!
回覆刪除