android脚步---APP引导页添加

package com.leadcore.uudatoutie;

import java.util.ArrayList;

import com.leadcore.uudatoutie.R;
import com.leadcore.uudatoutie.data.ViewPagerAdapter;

import android.app.Activity;
import android.content.Intent;
import android.graphics.drawable.Drawable;
import android.os.Bundle;
import android.support.v4.view.ViewPager;
import android.support.v4.view.ViewPager.OnPageChangeListener;
import android.view.LayoutInflater;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.ImageView;

public class GuideActivity extends Activity implements OnPageChangeListener{
    private ViewPager viewPager;

    private ViewPagerAdapter vpAdapter;

    private ArrayList<View> views;

    private View view1, view2, view3, view4;
    private ImageView mPage0, mPage1, mPage2, mPage3;
    
    private Button startBt;
        
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_guide);
        
        initView();
        
        initData();
    }

    private void initView() {
        LayoutInflater mLi = LayoutInflater.from(this);
        view1 = mLi.inflate(R.layout.guide_view01, null);
        view2 = mLi.inflate(R.layout.guide_view02, null);
        view3 = mLi.inflate(R.layout.guide_view03, null);
        view4 = mLi.inflate(R.layout.guide_view04, null);
    
        viewPager = (ViewPager) findViewById(R.id.viewpager);

        views = new ArrayList<View>();

        vpAdapter = new ViewPagerAdapter(views);
        
        startBt = (Button) view4.findViewById(R.id.startBtn);
        
        mPage0 = (ImageView)findViewById(R.id.page0);
        mPage1 = (ImageView)findViewById(R.id.page1);
        mPage2 = (ImageView)findViewById(R.id.page2);
        mPage3 = (ImageView)findViewById(R.id.page3);
        
        
    }

    private void initData() {
        viewPager.setOnPageChangeListener(this);
        viewPager.setAdapter(vpAdapter);

        views.add(view1);
        views.add(view2);
        views.add(view3);
        views.add(view4);        
                                
        startBt.setOnClickListener(new OnClickListener() {
            @Override
            public void onClick(View v) {
                 startbutton();
            }
        });
    }

    @Override
    public void onPageScrollStateChanged(int arg0) {
            
    }

    @Override
    public void onPageScrolled(int arg0, float arg1, int arg2) {
        
    }

    @Override
    public void onPageSelected(int pos) {
        Drawable page_now = getResources().getDrawable(R.drawable.indicator_page_now);
        Drawable page = getResources().getDrawable(R.drawable.indicator_page);
        switch (pos) {
        case 0:
            mPage0.setImageDrawable(page_now);
            mPage1.setImageDrawable(page);
            break;
        case 1:
            mPage1.setImageDrawable(page_now);
            mPage0.setImageDrawable(page);
            mPage2.setImageDrawable(page);
            break;
        case 2:
            mPage2.setImageDrawable(page_now);
            mPage1.setImageDrawable(page);
            mPage3.setImageDrawable(page);
            break;
        case 3:
            mPage3.setImageDrawable(page_now);
            mPage2.setImageDrawable(page);
            break;
        }
    }
    
    private void startbutton() {
        startActivity(new Intent(this, CameraActivity.class));
        this.finish();
      }
}

有四张引导页,page0,page1,page2,page3,放在资源文件drawable里面,

 

 

 

activity-guide.xml

<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical" >

    <android.support.v4.view.ViewPager
        android:id="@+id/viewpager"
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"
        android:background="@drawable/page_bg" />
    
         <LinearLayout
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:layout_gravity="bottom"
            android:layout_marginBottom="30dp" 
            android:gravity="center_horizontal"
            android:orientation="horizontal" >

            <ImageView
                android:id="@+id/page0"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:scaleType="matrix"
                android:src="@drawable/indicator_page_now" />
            <ImageView
                android:id="@+id/page1"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_marginLeft="10dp"
                android:scaleType="matrix"
                android:src="@drawable/indicator_page" />
            <ImageView
                android:id="@+id/page2"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_marginLeft="10dp"
                android:scaleType="matrix"
                android:src="@drawable/indicator_page" />
            <ImageView
                android:id="@+id/page3"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_marginLeft="10dp"
                android:scaleType="matrix"
                android:src="@drawable/indicator_page" />
            <!-- <ImageView
                android:id="@+id/page4"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_marginLeft="10dp"
                android:scaleType="matrix"
                android:src="@drawable/page" />
            <ImageView
                android:id="@+id/page5"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_marginLeft="10dp"
                android:scaleType="matrix"
                android:src="@drawable/page" /> -->
        </LinearLayout>
</FrameLayout>

 

posted @ 2014-11-28 10:40  Anita-ff  阅读(307)  评论(0编辑  收藏  举报