项目结构如图:
包的分类很明确,看名字就知道意思:
net.oschina.app下面的AppStart类是程序的启动页面
应用程序启动类:显示欢迎界面并跳转到主界面
final View view = View.inflate(this, R.layout.start, null);
setContentView(view);
//渐变展示启动屏
AlphaAnimation aa = new AlphaAnimation(0.3f,1.0f);
aa.setDuration(2000);
view.startAnimation(aa);
aa.setAnimationListener(new AnimationListener()
{
@Override
public void onAnimationEnd(Animation arg0) {
redirectTo();
}
@Override
public void onAnimationRepeat(Animation animation) {}
@Override
public void onAnimationStart(Animation animation) {}
});
24行的inflate,是找到启动也的xml配置文件
解释:setContentView()一旦调用, layout就会立刻显示UI;而inflate只会把Layout形成一个以view类实现成的对象,有需要时再用setContentView(view)显示出来。一般在activity中通过setContentView()将界面显示出来,但是如果在非activity中如何对控件布局设置操作了,这就需要LayoutInflater动态加载。
start.xml配置文件
<?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:orientation="vertical" android:layout_width="fill_parent" android:layout_height="fill_parent" android:gravity="bottom" android:background="@drawable/start_background"> </LinearLayout>
在动画里启动..Main这个activity
/**
* 跳转到...
*/
private void redirectTo(){
Intent intent = new Intent(this, Main.class);
startActivity(intent);
finish();
}