在IOS与Android之间纠结了很长一段时间,IOS相比Andriod确实有很多优秀的地方,但我是一个比较嫌麻烦的人,不喜欢切换在Window与Mac之间,果断选择Android进行了我的学习之旅;
本小节是第一个Activity,开始画面的淡入效果,不说废话,直接干货。
SplashActivity.java
1 package com.my1024.ui; 2 3 import android.app.Activity; 4 import android.content.Intent; 5 import android.os.Bundle; 6 import android.os.Handler; 7 import android.view.View; 8 import android.view.Window; 9 import android.view.WindowManager; 10 import android.view.animation.Animation; 11 import android.view.animation.Animation.AnimationListener; 12 import android.view.animation.AnimationUtils; 13 14 import com.my1024.R; 15 16 17 public class SplashActivity extends Activity { 18 19 private Handler mHandler = new Handler(); 20 21 @Override 22 protected void onCreate(Bundle savedInstanceState) { 23 super.onCreate(savedInstanceState); 24 View view=View.inflate(this, R.layout.start_activity, null); 25 26 //隐去标题栏(应用程序的名字) 27 this.requestWindowFeature(Window.FEATURE_NO_TITLE); 28 //隐去状态栏部分(电池等图标和一切修饰部分) 29 this.getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN); 30 31 setContentView(view); 32 Animation animation=AnimationUtils.loadAnimation(this, R.anim.alpha); 33 view.startAnimation(animation); 34 animation.setAnimationListener(new AnimationListener() { 35 @Override 36 public void onAnimationStart(Animation arg0) {} 37 @Override 38 public void onAnimationRepeat(Animation arg0) {} 39 40 @Override 41 public void onAnimationEnd(Animation arg0) { 42 mHandler.postDelayed(new Runnable() { 43 @Override 44 public void run() { 45 goHome(); 46 } 47 }, 500); 48 } 49 }); 50 } 51 52 protected void onResume() { 53 super.onResume(); 54 } 55 56 private void goHome() { 57 Intent intent=new Intent(this,MainActivity.class); 58 startActivity(intent); 59 super.finish(); 60 }; 61 62 }
start_activity.xml
1 <?xml version="1.0" encoding="utf-8"?> 2 <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" 3 android:layout_width="match_parent" 4 android:layout_height="match_parent" 5 android:background="@drawable/splash_load"> 6 </RelativeLayout>
下一节将讲述MainActivity与它小伙伴儿的故事,尽情等……