引导页+导航页

启动页布局
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:background="@drawable/b1i"
    android:layout_width="match_parent"
    android:layout_height="match_parent">
    <TextView
        android:id="@+id/tv_time"
    android:text="倒计时:"
    android:layout_width="100dp"
    android:gravity="center"
    android:layout_height="50dp"
    android:layout_alignParentBottom="true" />
    <TextView
        android:id="@+id/tv_jump"
        android:text="跳过->"
        android:layout_width="100dp"
        android:gravity="center"
        android:layout_height="50dp"
        android:layout_alignParentRight="true"
        android:layout_alignParentBottom="true"/>
</RelativeLayout>
启动页代码
public class QDActivity extends AppCompatActivity {
    int t=5;
    private TextView tvTime;
    private TextView tvJump;
    private SharedPreferences sharedPreferences;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_qd);
        initView();
        time();
    }
    public void initView(){
        sharedPreferences = this.getSharedPreferences("config", Context.MODE_PRIVATE);
        tvTime = (TextView) findViewById(R.id.tv_time);
        tvJump = (TextView) findViewById(R.id.tv_jump);
    }
    Handler handler = new Handler() {
        @Override
        public void handleMessage(Message msg) {
            // TODO Auto-generated method stub
            super.handleMessage(msg);
            if (msg.what == 1) {
                tvTime.setText("倒计时:"+t+"秒");
                if (t == 0) {
                    enter();
                }
            }
        }
    };

    private void enter() {
        //设置第一次进入状态
        if (sharedPreferences.getBoolean("b",true)){
            SharedPreferences.Editor edit = sharedPreferences.edit();
            edit.putBoolean("b",false);
            edit.commit();
            Intent intent = new Intent(QDActivity.this, YDActivity.class);
            startActivity(intent);
            finish();
        } else {
            Intent intent = new Intent(QDActivity.this, MainActivity.class);
            startActivity(intent);
            finish();
        }
    }

    public void time(){
        new Thread(new Runnable() {
            @Override
            public void run() {
                for (int i = 0; i < 5; i++) {
                    try {
                        Thread.sleep(1000);
                    } catch (InterruptedException e) {
                        // TODO Auto-generated catch block
                        e.printStackTrace();
                    }

                    t--;
                    handler.sendEmptyMessage(1);
                }
            }
        }).start();
    }
}

引导页布局

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    tools:context="com.example.fanjie.fanjie0109.YDActivity">
    <android.support.v4.view.ViewPager
        android:id="@+id/vp"
        android:layout_width="match_parent"
        android:layout_height="match_parent">
    </android.support.v4.view.ViewPager>
    <TextView
        android:layout_alignParentRight="true"
        android:layout_alignParentBottom="true"
        android:visibility="gone"
        android:text="去主页==>"
        android:id="@+id/gomain"
        android:layout_width="100dp"
        android:layout_height="50dp" />
</RelativeLayout>
引导页代码
public class YDActivity extends AppCompatActivity {

    private ViewPager viewPager;
    List<Img> list = new ArrayList<>();
    private TextView goMain;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_yd);
        viewPager = (ViewPager) findViewById(R.id.vp);
        goMain = (TextView) findViewById(R.id.gomain);
        list.add(new Img(R.drawable.yd1));
        list.add(new Img(R.drawable.yd2));
        list.add(new Img(R.drawable.yd3));
        viewPager.setAdapter(new Myadapter2());
        viewPager.setOnPageChangeListener(new ViewPager.OnPageChangeListener() {
            @Override
            public void onPageScrolled(int position, float positionOffset, int positionOffsetPixels) {
                if (viewPager.getCurrentItem()==2){
                    goMain.setVisibility(View.VISIBLE);
                    goMain.setOnClickListener(new View.OnClickListener() {
                        @Override
                        public void onClick(View view) {
                            Intent intent = new Intent(YDActivity.this, MainActivity.class);
                            startActivity(intent);
                            finish();
                        }
                    });
                }
            }

            @Override
            public void onPageSelected(int position) {

            }

            @Override
            public void onPageScrollStateChanged(int state) {

            }
        });
    }
    class Myadapter2 extends PagerAdapter {

        @Override
        public int getCount() {
            return list.size();
            //return Integer.MAX_VALUE;
        }

        @Override
        public boolean isViewFromObject(View view, Object object) {
            return view==object;
        }

        @Override
        public Object instantiateItem(ViewGroup container, int position) {
            View view = View.inflate(YDActivity.this, R.layout.vp, null);
            ImageView imageview3 = (ImageView)view.findViewById(R.id.imageView3);
            imageview3.setImageResource(list.get(position).getImg());
            container.addView(view);
            return view;
        }

        @Override
        public void destroyItem(ViewGroup container, int position, Object object) {
            container.removeView((View) object);
        }
    }
}
图片集合泛型实体类
public class Img {
    private int img;

    public Img(int img) {
        this.img = img;
    }

    public int getImg() {
        return img;
    }

    public void setImg(int img) {
        this.img = img;
    }
}



评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值