首頁 > 手機軟體

Android實現左右滑動的指引效果

2019-11-27 15:30:01

在一般情況下,Android左右滑動的指引效果是指在應用第一次啟動時,會顯示一些幫助介面,使用者可通過手指左右滑動來了解應用資訊。當使用者滑動到最後一頁時,可通過點選進入遊戲應用。


1

編寫引導介面布局檔案,內容如下:

activivty_guide_view_01.xml

<?xml version="1.0" encoding="utf-8"?>

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"

    android:layout_width="match_parent"

    android:layout_height="match_parent"

    android:layout_gravity="center"

    android:background="@color/textBgColor" >

    <LinearLayout

        android:id="@id/ll_guide_view_01_01"

        android:layout_width="match_parent"

        android:layout_height="20dp"

        android:orientation="vertical" />

    <LinearLayout

        android:id="@id/ll_guide_view_01_02"

        android:layout_width="match_parent"

        android:layout_height="wrap_content"

        android:layout_below="@id/ll_guide_view_01_01"

        android:background="@drawable/divider_horizontal_line"

        android:orientation="vertical" />

    <LinearLayout

        android:id="@id/ll_guide_view_01_03"

        android:layout_width="match_parent"

        android:layout_height="wrap_content"

        android:layout_below="@id/ll_guide_view_01_02"

        android:orientation="vertical" >

        <ImageView

            android:id="@id/iv_guide_view_01"

            android:layout_width="match_parent"

            android:layout_height="wrap_content"

            android:contentDescription="@string/gudie_view_01_image"

            android:src="@drawable/guide_view_01" />

    </LinearLayout>

    <LinearLayout

        android:id="@id/ll_guide_view_01_04"

        android:layout_width="match_parent"

        android:layout_height="wrap_content"

        android:layout_below="@id/ll_guide_view_01_03"

        android:layout_margin="@dimen/activity_guide_view_margin"

        android:background="@drawable/divider_horizontal_line"

        android:orientation="vertical" />

    <LinearLayout

        android:id="@id/ll_guide_view_01_05"

        android:layout_width="match_parent"

        android:layout_height="wrap_content"

        android:layout_below="@id/ll_guide_view_01_04"

        android:orientation="vertical" >

        <TextView

            android:id="@id/tv_guide_view_01"

            android:layout_width="wrap_content"

            android:layout_height="wrap_content"

            android:paddingLeft="@dimen/activity_guide_view_margin"

            android:paddingRight="@dimen/activity_guide_view_margin"

            android:text="@string/guide_view_01_text"

            android:textColor="@color/textColor"

            android:textSize="14sp" />

    </LinearLayout>

</RelativeLayout>


2

編寫引導介面的標頭檔案布局檔案,內容如下:activity_guide_view_item_header.xml<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"? ? android:layout_width="match_parent"? ? android:layout_height="wrap_content"? ? android:background="@drawable/guide_view_top_back_image"? ? android:orientation="horizontal" >? ? <L
inearLayout? ? ? ? android:layout_width="wrap_content"? ? ? ? android:layout_height="wrap_content"? ? ? ? android:layout_alignParentLeft="true"? ? ? ? android:layout_centerVertical="true"? ? ? ? android:layout_gravity="center_vertical"? ? ? ? android:layout_marginLeft="5dip"? ? ? ? android:gravity="center"? ? ? ? android:orientation="vertical" >? ? ? ? <TextView? ? ? ? ? ? android:id="@id/tv_guide_view_exit"? ? ? ? ? ? android:layout_width="wrap_content"? ? ? ? ? ? android:layout_height="wrap_content"? ? ? ? ? ? android:background="@drawable/gudie_view_btn_back_bg"? ? ? ? ? ? android:clickable="true"? ? ? ? ? ? android:gravity="center"? ? ? ? ? ? android:paddingLeft="@dimen/activity_guide_view_item_header_margin"? ? ? ? ? ? android:text="@string/exit"? ? ? ? ? ? android:textColor="@color/itemHeaderTextColor"? ? ? ? ? ? android:textSize="14sp" />? ? </LinearLayout>? ? <TextView? ? ? ? android:id="@id/tv_guide_view_title"? ? ? ? android:layout_width="wrap_content"? ? ? ? android:layout_height="wrap_content"? ? ? ? android:layout_centerInParent="true"? ? ? ? android:layout_centerVertical="true"? ? ? ? android:text="@string/app_name"? ? ? ? android:textColor="@color/itemHeaderTextColor"? ? ? ? android:textSize="16sp" />? ? <LinearLayout? ? ? ? android:layout_width="wrap_content"? ? ? ? android:layout_height="wrap_content"? ? ? ? android:layout_alignParentRight="true"? ? ? ? android:layout_centerVertical="true"? ? ? ? android:layout_gravity="center_vertical"? ? ? ? android:layout_marginRight="5dip"? ? ? ? android:gravity="center"? ? ? ? android:orientation="vertical" >? ? ? ? <TextView? ? ? ? ? ? android:id="@id/tv_guide_view_home"? ? ? ? ? ? android:layout_width="wrap_content"? ? ? ? ? ? android:layout_height="wrap_content"? ? ? ? ? ? android:background="@drawable/guide_view_btn_home_bg"? ? ? ? ? ? android:clickable="true"? ? ? ? ? ? android:gravity="center"? ? ? ? ? ? android:text="@string/home"? ? ? ? ? ? android:textColor="@color/itemHeaderTextColor"? ? ? ? ? ? android:textSize="14sp" />? ? </LinearLayout></RelativeLayout>
? android:layout_alignParentLeft="true"? ? ? ? android:layout_centerVertical="true"? ? ? ? android:layout_gravity="center_vertical"? ? ? ? android:layout_marginLeft="5dip"? ? ? ? android:gravity="center"? ? ? ? android:orientation="vertical" >? ? ? ? <TextView? ? ? ? ? ? android:id="@id/tv_guide_view_exit"? ? ? ? ? ? android:layout_width="wrap_content"? ? ? ? ? ? android:layout_height="wrap_content"? ? ? ? ? ? android:background="@drawable/gudie_view_btn_back_bg"? ? ? ? ? ? android:clickable="true"? ? ? ? ? ? android:gravity="center"? ? ? ? ? ? android:paddingLeft="@dimen/activity_guide_view_item_header_margin"? ? ? ? ? ? android:text="@string/exit"? ? ? ? ? ? android:textColor="@color/itemHeaderTextColor"? ? ? ? ? ? android:textSize="14sp" />? ? </LinearLayout>? ? <TextView? ? ? ? android:id="@id/tv_guide_view_title"? ? ? ? android:layout_width="wrap_content"? ? ? ? android:layout_height="wrap_content"? ? ? ? android:layout_centerInParent="true"? ? ? ? android:layout_centerVertical="true"? ? ? ? android:text="@string/app_name"? ? ? ? android:textColor="@color/itemHeaderTextColor"? ? ? ? android:textSize="16sp" />? ? <LinearLayout? ? ? ? android:layout_width="wrap_content"? ? ? ? android:layout_height="wrap_content"? ? ? ? android:layout_alignParentRight="true"? ? ? ? android:layout_centerVertical="true"? ? ? ? android:layout_gravity="center_vertical"? ? ? ? android:layout_marginRight="5dip"? ? ? ? android:gravity="center"? ? ? ? android:orientation="vertical" >? ? ? ? <TextView? ? ? ? ? ? android:id="@id/tv_guide_view_home"? ? ? ? ? ? android:layout_width="wrap_content"? ? ? ? ? ? android:layout_height="wrap_content"? ? ? ? ? ? android:background="@drawable/guide_view_btn_home_bg"? ? ? ? ? ? android:clickable="true"? ? ? ? ? ? android:gravity="center"? ? ? ? ? ? android:text="@string/home"? ? ? ? ? ? android:textColor="@color/itemHeaderTextColor"? ? ? ? ? ? android:textSize="14sp" />? ? </LinearLayout></RelativeLayout>

3

編寫引導介面Activity的布局檔案,內容如下:activity_guide_view.xml<?xml version="1.0" encoding="utf-8"?><FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"? ? android:layout_width="match_parent"? ? android:layout_height="match_parent"? ? android:orientation="vertical" >? ? <LinearLayout? ? ? ? android:layout_
width="match_parent"? ? ? ? android:layout_height="wrap_content"? ? ? ? android:orientation="vertical" >? ? ? ? <include? ? ? ? ? ? android:id="@+id/item_header"? ? ? ? ? ? layout="@layout/activity_guide_view_item_header" />? ? ? ? <android.support.v4.view.ViewPager? ? ? ? ? ? android:id="@id/vp_guide_view"? ? ? ? ? ? android:layout_width="match_parent"? ? ? ? ? ? android:layout_height="wrap_content" />? ? </LinearLayout>? ? <LinearLayout? ? ? ? android:layout_width="match_parent"? ? ? ? android:layout_height="wrap_content"? ? ? ? android:orientation="vertical" >? ? ? ? <RelativeLayout? ? ? ? ? ? android:layout_width="match_parent"? ? ? ? ? ? android:layout_height="wrap_content"? ? ? ? ? ? android:orientation="vertical" >? ? ? ? ? ? <LinearLayout? ? ? ? ? ? ? ? android:id="@id/ll_view_group"? ? ? ? ? ? ? ? android:layout_width="fill_parent"? ? ? ? ? ? ? ? android:layout_height="wrap_content"? ? ? ? ? ? ? ? android:layout_alignParentBottom="true"? ? ? ? ? ? ? ? android:layout_marginBottom="40dp"? ? ? ? ? ? ? ? android:gravity="center_horizontal"? ? ? ? ? ? ? ? android:orientation="horizontal" />? ? ? ? </RelativeLayout>? ? </LinearLayout></FrameLayout>
? ? ? ? <include? ? ? ? ? ? android:id="@+id/item_header"? ? ? ? ? ? layout="@layout/activity_guide_view_item_header" />? ? ? ? <android.support.v4.view.ViewPager? ? ? ? ? ? android:id="@id/vp_guide_view"? ? ? ? ? ? android:layout_width="match_parent"? ? ? ? ? ? android:layout_height="wrap_content" />? ? </LinearLayout>? ? <LinearLayout? ? ? ? android:layout_width="match_parent"? ? ? ? android:layout_height="wrap_content"? ? ? ? android:orientation="vertical" >? ? ? ? <RelativeLayout? ? ? ? ? ? android:layout_width="match_parent"? ? ? ? ? ? android:layout_height="wrap_content"? ? ? ? ? ? android:orientation="vertical" >? ? ? ? ? ? <LinearLayout? ? ? ? ? ? ? ? android:id="@id/ll_view_group"? ? ? ? ? ? ? ? android:layout_width="fill_parent"? ? ? ? ? ? ? ? android:layout_height="wrap_content"? ? ? ? ? ? ? ? android:layout_alignParentBottom="true"? ? ? ? ? ? ? ? android:layout_marginBottom="40dp"? ? ? ? ? ? ? ? android:gravity="center_horizontal"? ? ? ? ? ? ? ? android:orientation="horizontal" />? ? ? ? </RelativeLayout>? ? </LinearLayout></FrameLayout>

4

編寫引導介面Activity,其程式碼如下:/**?*??*/package com.i114gbox.aglieguy;import java.util.ArrayList;import java.util.List;import android.content.Context;import android.content.Intent;import android.os.Bundle;import android.os.Parcelable;import android.support.v4.view.PagerAdapter;import android.support.v4.view.ViewPager;imp
ort android.support.v4.view.ViewPager.OnPageChangeListener;import android.view.LayoutInflater;import android.view.View;import android.view.View.OnClickListener;import android.view.ViewGroup;import android.view.ViewGroup.LayoutParams;import android.widget.ImageView;import android.widget.TextView;import com.i114gbox.aglieguy.utils.CustomProgressDialogExitTaskUtils;import com.i114gbox.sdk.activity.I114gBoxActivity;import com.i114gbox.sdk.activity.dialog.I114gBoxProgressDialog;import com.i114gbox.sdk.config.I114gBoxConfig;import com.i114gbox.sdk.constant.I114gBoxConstant;import com.i114gbox.sdk.utils.I114gBoxCollectActivityUtils;import com.i114gbox.sdk.utils.I114gBoxLogUtils;import com.i114gbox.sdk.utils.I114gBoxResourceUtils;/**?* 引導Activity?*??* @author SJC?*??*/public class GuideViewActivity extends I114gBoxActivity implementsOnClickListener {private static String TAG = "GuideViewActivity";private Context ctx = null;private List<View> pageViews;private ImageView[] imageViews;private ImageView imageView;private ViewGroup main;private ViewGroup group;private ViewPager viewPager;private I114gBoxProgressDialog i114gBoxProgressDialog = null;private ViewGroup viewGroup;private int count;@Overrideprotected void onCreate(Bundle savedInstanceState) {I114gBoxLogUtils.d(TAG, "The onCreate method execute.");I114gBoxConfig.setDebugEnable(true);// 開啟LOGsuper.onCreate(savedInstanceState);I114gBoxCollectActivityUtils.getInstance().addActivity(this);// 收集Activityctx = this;count = mBaseSettings.getInt(I114gBoxConstant.PREFERENCE_KEY_LAUNCH_COUNT, 0);I114gBoxLogUtils.i(TAG, "count:" + count);if (count != 0) {// 當應用並不是第一次啟動時Intent intent = new Intent(ctx, MainActivity.class);ctx.startActivity(intent);overridePendingTransition(I114gBoxResourceUtils.getAnimId(ctx, "zoomin"),I114gBoxResourceUtils.getAnimId(ctx, "zoomout"));} else {// 當應用為第一次啟動時count++;mBaseSettings.edit().putInt(I114gBoxConstant.PREFERENCE_KEY_LAUNCH_COUNT, count).commit();LayoutInflater layoutInflater = getLayoutInflater();pageViews = new ArrayList<View>();// 載入左右滑動指引效果的圖片布局資源pageViews.add(layoutInflater.inflate(I114gBoxResourceUtils.getLayoutId(ctx, "activivty_guide_view_01"), null));pageViews.add(layoutInflater.inflate(I114gBoxResourceUtils.getLayoutId(ctx, "activivty_guide_view_02"), null));pageViews.add(layoutInflater.inflate(I114gBoxResourceUtils.getLayoutId(ctx, "activivty_guide_view_03"), null));pageViews.add(layoutInflater.inflate(I114gBoxResourceUtils.getLayoutId(ctx, "activivty_guide_view_04"), null));pageViews.add(layoutInflater.inflate(I114gBoxResourceUtils.getLayoutId(ctx, "activivty_guide_view_05"), null));pageViews.add(layoutInflater.inflate(I114gBoxResourceUtils.getLayoutId(ctx, "activivty_guide_view_06"), null));pageViews.add(layoutInflater.inflate(I114gBoxResourceUtils.getLayoutId(ctx, "activivty_guide_view_07"), null));imageViews = new ImageView[pageViews.size()];main = (ViewGroup) layoutInflater.inflate(I114gBoxResourceUtils.getLayoutId(ctx, "activity_guide_view"), null);group = (ViewGroup) main.findViewById(I114gBoxResourceUtils.getId(ctx, "ll_view_group"));viewPager = (ViewPager) main.findViewById(I114gBoxResourceUtils.getId(ctx, "vp_guide_view"));for (int i = 0; i < pageViews.size(); i++) {imageView = new ImageView(ctx);imageView.setLayoutParams(new LayoutParams(20, 20));imageView.setPadding(20, 0, 20, 0);imageViews[i] = imageView;// 預設第一張圖為顯示狀態if (i == 0) {imageViews[i].setBackgroundResource(I114gBoxResourceUtils.getDrawableId(ctx,"guide_view_page_indicator_focused"));} else {imageViews[i].setBackgroundResource(I114gBoxResourceUtils.getDrawableId(ctx, "guide_view_page_indicator"));}group.addView(imageViews[i]);}// 設定佈局檔案setContentView(main);// 設定引導介面介面卡viewPager.setAdapter(new GuideViewPagerAdapter());// 設定引導介面監聽器viewPager.setOnPageChangeListener(new GuideViewPageChangeListener());TextView guideExitTextView = (TextView) main.findViewById(I114gBoxResourceUtils.getId(ctx,"tv_guide_view_exit"));TextView guideHomeTextView = (TextView) main.findViewById(I114gBoxResourceUtils.getId(ctx,"tv_guide_view_home"));viewGroup = (ViewGroup) layoutInflater.inflate(I114gBoxResourceUtils.getLayoutId(ctx,"activivty_guide_view_07"), null);guideExitTextView.setOnClickListener(this);guideHomeTextView.setOnClickListener(this);}}/*** 引導介面介面卡*?* @author SJC*?*/class GuideViewPagerAdapter extends PagerAdapter {/** 獲取指引的數量 **/@Overridepublic int getCount() {return pageViews.size();}@Overridepublic boolean isViewFromObject(View arg0, Object arg1) {I114gBoxLogUtils.d("GuideViewPagerAdapter","The isViewFromObject method execute.");return arg0 == arg1;}/** 獲取指引的位置 **/@Overridepublic int getItemPosition(Object object) {I114gBoxLogUtils.d("GuideViewPagerAdapter","The getItemPosition method execute.");I114gBoxLogUtils.i("GuideViewPagerAdapter", "The item position:"+ super.getItemPosition(object));return super.getItemPosition(object);}@Overridepublic void destroyItem(ViewGroup container, int position, Object object) {I114gBoxLogUtils.d("GuideViewPagerAdapter","The destroyItem method execute.");I114gBoxLogUtils.i("GuideViewPagerAdapter", "position:" + position);container.removeView(pageViews.get(position));}@Overridepublic Object instantiateItem(ViewGroup container, int position) {I114gBoxLogUtils.d("GuideViewPagerAdapter","The instantiateItem method execute.");I114gBoxLogUtils.i("GuideViewPagerAdapter", "position:" + position);container.addView(pageViews.get(position));return pageViews.get(position);}@Overridepublic void restoreState(Parcelable state, ClassLoader loader) {I114gBoxLogUtils.d("GuideViewPagerAdapter","The restoreState method execute.");super.restoreState(state, loader);}@Overridepublic Parcelable saveState() {I114gBoxLogUtils.d("GuideViewPagerAdapter","The saveState method execute.");return super.saveState();}}/*** 引導介面監聽器*?* @author SJC*?*/class GuideViewPageChangeListener implements OnPageChangeListener {@Overridepublic void onPageScrollStateChanged(int arg0) {I114gBoxLogUtils.d("GuideViewPageChangeListener","The onPageScrollStateChanged method execute.");I114gBoxLogUtils.i(TAG, "arg0:" + arg0);}@Overridepublic void onPageScrolled(int arg0, float arg1, int arg2) {I114gBoxLogUtils.d("GuideViewPageChangeListener","The onPageScrolled method execute.");I114gBoxLogUtils.i("GuideViewPageChangeListener", "arg0:" + arg0+ "|" + "arg1:" + arg1 + "|" + "arg2:" + arg2);}@Overridepublic void onPageSelected(int arg0) {I114gBoxLogUtils.d("GuideViewPageChangeListener","The onPageSelected method execute.");I114gBoxLogUtils.i("GuideViewPageChangeListener", "arg0:" + arg0);for (int i = 0; i < imageViews.length; i++) {imageViews[arg0].setBackgroundResource(I114gBoxResourceUtils.getDrawableId(ctx,"guide_view_page_indicator_focused"));if (arg0 != i) {imageViews[i].setBackgroundResource(I114gBoxResourceUtils.getDrawableId(ctx, "guide_view_page_indicator"));}}}}@Overridepublic void onClick(View v) {if (v.getId() == I114gBoxResourceUtils.getId(ctx, "tv_guide_view_exit")) {CustomProgressDialogExitTaskUtils customProgressDialogAsyncTaskUtils = new CustomProgressDialogExitTaskUtils(ctx, i114gBoxProgressDialog);customProgressDialogAsyncTaskUtils.execute(2000);// 執行Task} else if (v.getId() == I114gBoxResourceUtils.getId(ctx,"tv_guide_view_home")) {Intent intent = new Intent(ctx, MainActivity.class);ctx.startActivity(intent);overridePendingTransition(I114gBoxResourceUtils.getAnimId(ctx, "zoomin"),I114gBoxResourceUtils.getAnimId(ctx, "zoomout"));}}@Overrideprotected void onDestroy() {I114gBoxLogUtils.d(TAG, "The onDestory method execute.");if (null != i114gBoxProgressDialog) {i114gBoxProgressDialog.dismiss();i114gBoxProgressDialog = null;}super.onDestroy();}/** 進入遊戲 **/public void enterGame(View view) {I114gBoxLogUtils.d(TAG, "enter game");Intent intent = new Intent(viewGroup.getContext(), MainActivity.class);viewGroup.getContext().startActivity(intent);overridePendingTransition(I114gBoxResourceUtils.getAnimId(ctx, "zoomin"),I114gBoxResourceUtils.getAnimId(ctx, "zoomout"));}}
roid.view.View;import android.view.View.OnClickListener;import android.view.ViewGroup;import android.view.ViewGroup.LayoutParams;import android.widget.ImageView;import android.widget.TextView;import com.i114gbox.aglieguy.utils.CustomProgressDialogExitTaskUtils;import com.i114gbox.sdk.activity.I114gBoxActivity;import com.i114gbox.sdk.activity.dialog.I114gBoxProgressDialog;import com.i114gbox.sdk.config.I114gBoxConfig;import com.i114gbox.sdk.constant.I114gBoxConstant;import com.i114gbox.sdk.utils.I114gBoxCollectActivityUtils;import com.i114gbox.sdk.utils.I114gBoxLogUtils;import com.i114gbox.sdk.utils.I114gBoxResourceUtils;/**?* 引導Activity?*??* @author SJC?*??*/public class GuideViewActivity extends I114gBoxActivity implementsOnClickListener {private static String TAG = "GuideViewActivity";private Context ctx = null;private List<View> pageViews;private ImageView[] imageViews;private ImageView imageView;private ViewGroup main;private ViewGroup group;private ViewPager viewPager;private I114gBoxProgressDialog i114gBoxProgressDialog = null;private ViewGroup viewGroup;private int count;@Overrideprotected void onCreate(Bundle savedInstanceState) {I114gBoxLogUtils.d(TAG, "The onCreate method execute.");I114gBoxConfig.setDebugEnable(true);// 開啟LOGsuper.onCreate(savedInstanceState);I114gBoxCollectActivityUtils.getInstance().addActivity(this);// 收集Activityctx = this;count = mBaseSettings.getInt(I114gBoxConstant.PREFERENCE_KEY_LAUNCH_COUNT, 0);I114gBoxLogUtils.i(TAG, "count:" + count);if (count != 0) {// 當應用並不是第一次啟動時Intent intent = new Intent(ctx, MainActivity.class);ctx.startActivity(intent);overridePendingTransition(I114gBoxResourceUtils.getAnimId(ctx, "zoomin"),I114gBoxResourceUtils.getAnimId(ctx, "zoomout"));} else {// 當應用為第一次啟動時count++;mBaseSettings.edit().putInt(I114gBoxConstant.PREFERENCE_KEY_LAUNCH_COUNT, count).commit();LayoutInflater layoutInflater = getLayoutInflater();pageViews = new ArrayList<View>();// 載入左右滑動指引效果的圖片布局資源pageViews.add(layoutInflater.inflate(I114gBoxResourceUtils.getLayoutId(ctx, "activivty_guide_view_01"), null));pageViews.add(layoutInflater.inflate(I114gBoxResourceUtils.getLayoutId(ctx, "activivty_guide_view_02"), null));pageViews.add(layoutInflater.inflate(I114gBoxResourceUtils.getLayoutId(ctx, "activivty_guide_view_03"), null));pageViews.add(layoutInflater.inflate(I114gBoxResourceUtils.getLayoutId(ctx, "activivty_guide_view_04"), null));pageViews.add(layoutInflater.inflate(I114gBoxResourceUtils.getLayoutId(ctx, "activivty_guide_view_05"), null));pageViews.add(layoutInflater.inflate(I114gBoxResourceUtils.getLayoutId(ctx, "activivty_guide_view_06"), null));pageViews.add(layoutInflater.inflate(I114gBoxResourceUtils.getLayoutId(ctx, "activivty_guide_view_07"), null));imageViews = new ImageView[pageViews.size()];main = (ViewGroup) layoutInflater.inflate(I114gBoxResourceUtils.getLayoutId(ctx, "activity_guide_view"), null);group = (ViewGroup) main.findViewById(I114gBoxResourceUtils.getId(ctx, "ll_view_group"));viewPager = (ViewPager) main.findViewById(I114gBoxResourceUtils.getId(ctx, "vp_guide_view"));for (int i = 0; i < pageViews.size(); i++) {imageView = new ImageView(ctx);imageView.setLayoutParams(new LayoutParams(20, 20));imageView.setPadding(20, 0, 20, 0);imageViews[i] = imageView;// 預設第一張圖為顯示狀態if (i == 0) {imageViews[i].setBackgroundResource(I114gBoxResourceUtils.getDrawableId(ctx,"guide_view_page_indicator_focused"));} else {imageViews[i].setBackgroundResource(I114gBoxResourceUtils.getDrawableId(ctx, "guide_view_page_indicator"));}group.addView(imageViews[i]);}// 設定佈局檔案setContentView(main);// 設定引導介面介面卡viewPager.setAdapter(new GuideViewPagerAdapter());// 設定引導介面監聽器viewPager.setOnPageChangeListener(new GuideViewPageChangeListener());TextView guideExitTextView = (TextView) main.findViewById(I114gBoxResourceUtils.getId(ctx,"tv_guide_view_exit"));TextView guideHomeTextView = (TextView) main.findViewById(I114gBoxResourceUtils.getId(ctx,"tv_guide_view_home"));viewGroup = (ViewGroup) layoutInflater.inflate(I114gBoxResourceUtils.getLayoutId(ctx,"activivty_guide_view_07"), null);guideExitTextView.setOnClickListener(this);guideHomeTextView.setOnClickListener(this);}}/*** 引導介面介面卡*?* @author SJC*?*/class GuideViewPagerAdapter extends PagerAdapter {/** 獲取指引的數量 **/@Overridepublic int getCount() {return pageViews.size();}@Overridepublic boolean isViewFromObject(View arg0, Object arg1) {I114gBoxLogUtils.d("GuideViewPagerAdapter","The isViewFromObject method execute.");return arg0 == arg1;}/** 獲取指引的位置 **/@Overridepublic int getItemPosition(Object object) {I114gBoxLogUtils.d("GuideViewPagerAdapter","The getItemPosition method execute.");I114gBoxLogUtils.i("GuideViewPagerAdapter", "The item position:"+ super.getItemPosition(object));return super.getItemPosition(object);}@Overridepublic void destroyItem(ViewGroup container, int position, Object object) {I114gBoxLogUtils.d("GuideViewPagerAdapter","The destroyItem method execute.");I114gBoxLogUtils.i("GuideViewPagerAdapter", "position:" + position);container.removeView(pageViews.get(position));}@Overridepublic Object instantiateItem(ViewGroup container, int position) {I114gBoxLogUtils.d("GuideViewPagerAdapter","The instantiateItem method execute.");I114gBoxLogUtils.i("GuideViewPagerAdapter", "position:" + position);container.addView(pageViews.get(position));return pageViews.get(position);}@Overridepublic void restoreState(Parcelable state, ClassLoader loader) {I114gBoxLogUtils.d("GuideViewPagerAdapter","The restoreState method execute.");super.restoreState(state, loader);}@Overridepublic Parcelable saveState() {I114gBoxLogUtils.d("GuideViewPagerAdapter","The saveState method execute.");return super.saveState();}}/*** 引導介面監聽器*?* @author SJC*?*/class GuideViewPageChangeListener implements OnPageChangeListener {@Overridepublic void onPageScrollStateChanged(int arg0) {I114gBoxLogUtils.d("GuideViewPageChangeListener","The onPageScrollStateChanged method execute.");I114gBoxLogUtils.i(TAG, "arg0:" + arg0);}@Overridepublic void onPageScrolled(int arg0, float arg1, int arg2) {I114gBoxLogUtils.d("GuideViewPageChangeListener","The onPageScrolled method execute.");I114gBoxLogUtils.i("GuideViewPageChangeListener", "arg0:" + arg0+ "|" + "arg1:" + arg1 + "|" + "arg2:" + arg2);}@Overridepublic void onPageSelected(int arg0) {I114gBoxLogUtils.d("GuideViewPageChangeListener","The onPageSelected method execute.");I114gBoxLogUtils.i("GuideViewPageChangeListener", "arg0:" + arg0);for (int i = 0; i < imageViews.length; i++) {imageViews[arg0].setBackgroundResource(I114gBoxResourceUtils.getDrawableId(ctx,"guide_view_page_indicator_focused"));if (arg0 != i) {imageViews[i].setBackgroundResource(I114gBoxResourceUtils.getDrawableId(ctx, "guide_view_page_indicator"));}}}}@Overridepublic void onClick(View v) {if (v.getId() == I114gBoxResourceUtils.getId(ctx, "tv_guide_view_exit")) {CustomProgressDialogExitTaskUtils customProgressDialogAsyncTaskUtils = new CustomProgressDialogExitTaskUtils(ctx, i114gBoxProgressDialog);customProgressDialogAsyncTaskUtils.execute(2000);// 執行Task} else if (v.getId() == I114gBoxResourceUtils.getId(ctx,"tv_guide_view_home")) {Intent intent = new Intent(ctx, MainActivity.class);ctx.startActivity(intent);overridePendingTransition(I114gBoxResourceUtils.getAnimId(ctx, "zoomin"),I114gBoxResourceUtils.getAnimId(ctx, "zoomout"));}}@Overrideprotected void onDestroy() {I114gBoxLogUtils.d(TAG, "The onDestory method execute.");if (null != i114gBoxProgressDialog) {i114gBoxProgressDialog.dismiss();i114gBoxProgressDialog = null;}super.onDestroy();}/** 進入遊戲 **/public void enterGame(View view) {I114gBoxLogUtils.d(TAG, "enter game");Intent intent = new Intent(viewGroup.getContext(), MainActivity.class);viewGroup.getContext().startActivity(intent);overridePendingTransition(I114gBoxResourceUtils.getAnimId(ctx, "zoomin"),I114gBoxResourceUtils.getAnimId(ctx, "zoomout"));}}

IT145.com E-mail:sddin#qq.com