安卓开发 简单的启动页

来源:互联网 发布:ghost 备份 linux 错误 编辑:程序博客网 时间:2024/05/04 01:31

启动页

1.我们一般在主页前面加启动页 今天我写的是最普通的一种 也是最简单的一种 把一张图片作为启动页

2.我们需要更改的只有两个 一个是xml文件一个是.java文件 另外在drawable里面放一张作为启动页的图片

代码实现部分

在需要增加启动页的布局文件里把LinearLayout改为ViewFlipper

并在主界面代码片段上面加一个单独的界面

<ViewFlipper xmlns:android="http://schemas.android.com/apk/res/android"    android:id="@+id/allFlipper"    android:layout_width="fill_parent"    android:layout_height="fill_parent" >    <!-- 启动等待界面 -->    <RelativeLayout        android:id="@+id/splashLayout"        android:layout_width="fill_parent"        android:layout_height="fill_parent"        android:background="@drawable/start" >    </RelativeLayout>    <!-- 主界面 -->    <RelativeLayout        android:id="@+id/homeLayout"        android:layout_width="fill_parent"        android:layout_height="wrap_content" >        <TextView            android:layout_width="fill_parent"            android:layout_height="wrap_content"            android:text="hello word" />    </RelativeLayout></ViewFlipper>

然后在MainActivity里面

oncreate上面加

private ViewFlipper allFlipper;private Handler handler = new Handler(){    @Override    public void handleMessage(Message msg) {        // TODO Auto-generated method stub        switch (msg.what) {            case 1:                //切换到主页面                allFlipper.setDisplayedChild(1);                break;        }    }};oncreate里面
super.onCreate(savedInstanceState);setContentView(R.layout.activity_main);的下面加 allFlipper = (ViewFlipper) findViewById(R.id.allFlipper);new Handler().postDelayed(new Runnable() {    @Override    public void run() {        handler.sendEmptyMessage(1); //UI主线程发送消息    }}, 3000); //启动等待3秒钟
就完成了
代码片段截图如下


0 0