之前一直很喜歡Lofter的啓動畫面,今天剛好項目需要,自己嘗試用自己的方式去實現,代碼相對比較簡單,並沒有複雜的地方,這裏就直接po上代碼了,也不多講解了,這個估計一看就懂了的。當然沒糾結在佈局上,所以,不是很認真的在佈局上下工夫,實現功能爲主:
XML佈局代碼如下:
splash.xml
<?xml version="1.0" encoding="utf-8"?>
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#D30F11" >
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent" >
<RelativeLayout
android:id="@+id/layout_firstIn"
android:layout_width="match_parent"
android:layout_height="120dp"
android:layout_alignParentBottom="true"
android:orientation="horizontal" >
<ImageView
android:id="@+id/image_c"
android:layout_width="100dp"
android:layout_height="100dp"
android:layout_marginLeft="150dp"
android:layout_marginTop="24dp"
android:layout_marginBottom="30dp"
android:src="@drawable/logo" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignBottom="@+id/image_c"
android:layout_toRightOf="@+id/image_c"
android:text="SDN"
android:textColor="@android:color/white"
android:textSize="50sp" />
</RelativeLayout>
</RelativeLayout>
<RelativeLayout
android:id="@+id/layout_secondIn"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@drawable/init_pic"
android:visibility="invisible" >
</RelativeLayout>
</FrameLayout>
程序的代碼實現如下:
public class SplashActivity extends Activity {
private RelativeLayout img_secondIn;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.splash);
img_secondIn = (RelativeLayout) findViewById(R.id.layout_secondIn);
img_secondIn.setVisibility(View.VISIBLE);
AlphaAnimation aa = new AlphaAnimation(0.0f, 1.0f);
aa.setDuration(5000);
img_secondIn.startAnimation(aa);
aa.setAnimationListener(new AnimationListener() {
// 動畫開始時便調用此方法
@Override
public void onAnimationStart(Animation animation) {
}
// 動畫重複播放時調用此方法
@Override
public void onAnimationRepeat(Animation animation) {
}
// 動畫結束時調用此方法
@Override
public void onAnimationEnd(Animation animation) {
Intent intent = new Intent(SplashActivity.this,
MainActivity.class);
startActivity(intent);
}
});
}
}
也就這樣而已,圖就不上了,那就傳下demo地址吧: