安卓入门:启动界面制作

时间:2022-05-22 16:17:24

由于刚刚开始学安卓,很多东西都不懂。昨天就启动界面制作进行了学习和大家分享一下。

启动界面实际上也是一个Activity,我们在layout中进行定义。 1.新建一个screen.xml,代码如下图所示:
<?xml version="1.0"  encoding="UTF-8"?>
<LinearLayout
android:id="@+id/loginRoot"
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical"
android:background="@drawable/welcome">


</LinearLayout>

2.新建一个类,继承于activity:

package com.example.uidesgin;

import android.app.Activity;
import android.app.Dialog;
import android.content.Intent;
import android.os.Bundle;
import android.os.Handler;
import android.view.Window;

public class ActSplashScreen extends Activity {

@Override
protected void onCreate(Bundle savedInstanceState) {
// TODO Auto-generated method stub
super.onCreate(savedInstanceState);
// 去掉标题
requestWindowFeature(Window.FEATURE_NO_TITLE);
setContentView(R.layout.actsplashscreen);
// 闪屏核心代码
new Handler().postDelayed(new Runnable() {

@Override
public void run() {
// TODO Auto-generated method stub
Intent intent = new Intent(ActSplashScreen.this,
MainActivity.class);
// 从启动动画切换到主界面
startActivity(intent);
ActSplashScreen.this.finish();// 结束动画
}
}, 3000);
}

}

3.最后记得在androidMainifest.xml中添加activity配置。并且设置成第一个启动
<activity
android:name="com.example.uidesgin.ActSplashScreen"
android:configChanges="orientation|keyboardHidden|screenSize"
android:label="@string/app_name"
android:theme="@android:style/Theme.NoTitleBar.Fullscreen" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />

<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>

这样我们的启动动画就制作完成了。


下面是DEMO的下载

DEMO.RAR