欢迎使用CSDN-markdown编辑器

android引导页开发

开发流程

  • 添加activity[SplashActivity,HomeActivity,GuideActivity,ViewPageAdapter]及Splash和Guide的相关布局

  • 考虑第一次进入引导页,否则进入主页面的实现

初始化的时候

protected void inint() {
        // 读取SharedPreferences中需要的数据
        // 使用SharedPreferences来记录程序的使用次数
        SharedPreferences sp = getSharedPreferences(
                SHAREDPREFERENCES_NAME_ISFIRST, MODE_PRIVATE);
        // 取得相应的值,如果没有该值,说明还未写入,用true作为默认值
        isfirst_flag = sp.getBoolean("isfirst_flag", true);

        if(!isfirst_flag){

            mHandler.sendEmptyMessageDelayed(GO_HOME, SPLASH_DELAY_MILLIS);
        }else{
            mHandler.sendEmptyMessageDelayed(GO_GUIDE, SPLASH_DELAY_MILLIS1);
        }

    }

使用Handler 发送消息

private Handler mHandler = new Handler() {
        public void handleMessage(Message msg) {
            switch (msg.what) {
            case GO_HOME:
                goHome();
                break;
            case GO_GUIDE:
                goGuide();
                break;
            }
        }
    };
  • GuideActivity内容及ViewPager
    GuideActivity的布局文件,使用相对布局+线性布局的方式
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:background="@color/white" >

    <android.support.v4.view.ViewPager
        android:id="@+id/vPager"
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"
         />
    <LinearLayout
        android:id="@+id/ll"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentBottom="true"
        android:layout_centerHorizontal="true"
        android:layout_marginBottom="5.0dp"
        android:orientation="horizontal" >

        <ImageView
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_gravity="center_vertical"
            android:clickable="true"
            android:padding="15.0dip"
            android:src="@drawable/dots" />

        <ImageView
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_gravity="center_vertical"
            android:clickable="true"
            android:padding="15.0dip"
            android:src="@drawable/dots" />
        <ImageView
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_gravity="center_vertical"
            android:clickable="true"
            android:padding="15.0dip"
            android:src="@drawable/dots" />
        <ImageView
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_gravity="center_vertical"
            android:clickable="true"
            android:padding="15.0dip"
            android:src="@drawable/dots" />

    </LinearLayout>      
</RelativeLayout>
  • ViewPageAdapter及添加guide_item布局文件
    注意其中还是采用的相对布局
<?xml version="1.0" encoding="UTF-8"?>
<RelativeLayout  xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    >
    <ImageView
        android:id="@+id/image"
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"
         />
    <Button
        android:visibility="gone"
        android:id="@+id/go_home"
        android:layout_width="200dp"
        android:layout_height="wrap_content"
        android:layout_alignParentBottom="true"
        android:layout_centerHorizontal="true"
        android:layout_marginBottom="50.0dp"
        android:clickable="true"
        android:padding="15.0dip"
        android:text="进入主页"/>    
</RelativeLayout>
  • 添加引导页下面的小圆点
ll = (LinearLayout) findViewById(R.id.ll);
        dots = new ImageView[views.size()];
        //循环取得小点图片
        for(int i = 0; i<images_slide.length;i++)
        {
            dots[i] = (ImageView)ll.getChildAt(i);
            // 下面小点,初始化所有项都使能状态       
            dots[i].setEnabled(true);
            //设置位置tag,方便取出与当前位置对应
            dots[i].setTag(i);
        }
        currentIndex = 0;
        dots[currentIndex].setEnabled(false);//设置为白色,即选中状态。

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值