之前一直很喜欢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地址吧: