viewpage 实现左右循环滑动

转载请注明,私人商业用途均可。

目标

类似用户引导页,可以滑动,左右滑动已经有大量实现,但循环滑动实现较少或者实现的效果不是很好。

效果不好主要体现在大概以下四个方面:图片少的时候会崩溃、单张图片的时候引导点存在、最后一张与第一张图片之间的滑动效果不自然、没有自动播放。

故此处实现任何图片的左右自然的循环滑动以及自动播放。

使用场景

1.用户引导页,多张图片

2.图片浏览,图片本地或者网络(网络时会出现图片可能为0、1的特殊情况)

实现方式

1.首末图片添加。最后一张图片后再加一张图片(第一张),第一张图片前加一个图片(最后一张),然后这样ViewPager一共有N+2页,在ViewPager的setOnPageChangeListener的onPageSelected()里面检测到当前页面索引为0时,setCurrentItem为N-2(左滑),当索引为N+1时,设置setCurrentItem为1(右滑)。其他的不便,这样便可实现循环左右滑动,但是首位图片滑动效果不自然,会突然跳过去。

2.重写ViewPager.OntouchListener。方法基本同上。效果不好

<p style="line-height:22px; margin-top:10px; margin-bottom:10px; font-family:Arial,Helvetica,sans-serif; white-space:normal; background-color:rgb(217,217,217)">    private int lastX = 0;// 获得当前X坐标</p><p style="line-height:22px; margin-top:10px; margin-bottom:10px; font-family:Arial,Helvetica,sans-serif; white-space:normal; background-color:rgb(217,217,217)">    private boolean mSlideLock = false;// 滑动锁,解决从最后一页向右滑动以及从第一页向左滑出现的多次滑动的问题</p><p style="line-height:22px; margin-top:10px; margin-bottom:10px; font-family:Arial,Helvetica,sans-serif; white-space:normal; background-color:rgb(217,217,217)">    private final static int LOCK_TIME = 5000;</p><p style="line-height:22px; margin-top:10px; margin-bottom:10px; font-family:Arial,Helvetica,sans-serif; white-space:normal; background-color:rgb(217,217,217)">      </p><p style="line-height:22px; margin-top:10px; margin-bottom:10px; font-family:Arial,Helvetica,sans-serif; white-space:normal; background-color:rgb(217,217,217)">        mViewPager.setOnTouchListener(new OnTouchListener() {</p><p style="line-height:22px; margin-top:10px; margin-bottom:10px; font-family:Arial,Helvetica,sans-serif; white-space:normal; background-color:rgb(217,217,217)"> </p><p style="line-height:22px; margin-top:10px; margin-bottom:10px; font-family:Arial,Helvetica,sans-serif; white-space:normal; background-color:rgb(217,217,217)">            @Override</p><p style="line-height:22px; margin-top:10px; margin-bottom:10px; font-family:Arial,Helvetica,sans-serif; white-space:normal; background-color:rgb(217,217,217)">            public boolean onTouch(View v, MotionEvent event) {</p><p style="line-height:22px; margin-top:10px; margin-bottom:10px; font-family:Arial,Helvetica,sans-serif; white-space:normal; background-color:rgb(217,217,217)">                switch (event.getAction()) {</p><p style="line-height:22px; margin-top:10px; margin-bottom:10px; font-family:Arial,Helvetica,sans-serif; white-space:normal; background-color:rgb(217,217,217)">                case MotionEvent.ACTION_DOWN:</p><p style="line-height:22px; margin-top:10px; margin-bottom:10px; font-family:Arial,Helvetica,sans-serif; white-space:normal; background-color:rgb(217,217,217)">                    lastX = (int) event.getX();</p><p style="line-height:22px; margin-top:10px; margin-bottom:10px; font-family:Arial,Helvetica,sans-serif; white-space:normal; background-color:rgb(217,217,217)">                    break;</p><p style="line-height:22px; margin-top:10px; margin-bottom:10px; font-family:Arial,Helvetica,sans-serif; white-space:normal; background-color:rgb(217,217,217)">                case MotionEvent.ACTION_UP:</p><p style="line-height:22px; margin-top:10px; margin-bottom:10px; font-family:Arial,Helvetica,sans-serif; white-space:normal; background-color:rgb(217,217,217)">                    Log.i("ViewPrivatePhotoTag", "当前项:"+mViewPager.getCurrentItem() +",总项数:" +mViewPager</p><p style="line-height:22px; margin-top:10px; margin-bottom:10px; font-family:Arial,Helvetica,sans-serif; white-space:normal; background-color:rgb(217,217,217)">                            .getAdapter().getCount());</p><p style="line-height:22px; margin-top:10px; margin-bottom:10px; font-family:Arial,Helvetica,sans-serif; white-space:normal; background-color:rgb(217,217,217)">                    if (!mSlideLock) {</p><p style="line-height:22px; margin-top:10px; margin-bottom:10px; font-family:Arial,Helvetica,sans-serif; white-space:normal; background-color:rgb(217,217,217)">                        if ((lastX - event.getX() > 100)</p><p style="line-height:22px; margin-top:10px; margin-bottom:10px; font-family:Arial,Helvetica,sans-serif; white-space:normal; background-color:rgb(217,217,217)">                                && (mViewPager.getCurrentItem() == mViewPager</p><p style="line-height:22px; margin-top:10px; margin-bottom:10px; font-family:Arial,Helvetica,sans-serif; white-space:normal; background-color:rgb(217,217,217)">                                        .getAdapter().getCount() - 1)) {// 从最后一页向右滑动</p><p style="line-height:22px; margin-top:10px; margin-bottom:10px; font-family:Arial,Helvetica,sans-serif; white-space:normal; background-color:rgb(217,217,217)">                            mViewPager.setCurrentItem(0,true);</p><p style="line-height:22px; margin-top:10px; margin-bottom:10px; font-family:Arial,Helvetica,sans-serif; white-space:normal; background-color:rgb(217,217,217)">                            </p><p style="line-height:22px; margin-top:10px; margin-bottom:10px; font-family:Arial,Helvetica,sans-serif; white-space:normal; background-color:rgb(217,217,217)">                            mSlideLock = true;</p><p style="line-height:22px; margin-top:10px; margin-bottom:10px; font-family:Arial,Helvetica,sans-serif; white-space:normal; background-color:rgb(217,217,217)">                            new Handler().postDelayed(new Runnable() {</p><p style="line-height:22px; margin-top:10px; margin-bottom:10px; font-family:Arial,Helvetica,sans-serif; white-space:normal; background-color:rgb(217,217,217)">                                @Override</p><p style="line-height:22px; margin-top:10px; margin-bottom:10px; font-family:Arial,Helvetica,sans-serif; white-space:normal; background-color:rgb(217,217,217)">                                public void run() { }, LOCK_TIME);</p><p style="line-height:22px; margin-top:10px; margin-bottom:10px; font-family:Arial,Helvetica,sans-serif; white-space:normal; background-color:rgb(217,217,217)">                        } else if ((lastX - event.getX() < -100)</p><p style="line-height:22px; margin-top:10px; margin-bottom:10px; font-family:Arial,Helvetica,sans-serif; white-space:normal; background-color:rgb(217,217,217)">                                && (mViewPager.getCurrentItem() == 0)) {// 从第一页向左滑</p><p style="line-height:22px; margin-top:10px; margin-bottom:10px; font-family:Arial,Helvetica,sans-serif; white-space:normal; background-color:rgb(217,217,217)">                            mViewPager.setCurrentItem(mViewPager.getAdapter().getCount()-1);</p><p style="line-height:22px; margin-top:10px; margin-bottom:10px; font-family:Arial,Helvetica,sans-serif; white-space:normal; background-color:rgb(217,217,217)">                            mSlideLock = true;</p><p style="line-height:22px; margin-top:10px; margin-bottom:10px; font-family:Arial,Helvetica,sans-serif; white-space:normal; background-color:rgb(217,217,217)">                            new Handler().postDelayed(new Runnable() {</p><p style="line-height:22px; margin-top:10px; margin-bottom:10px; font-family:Arial,Helvetica,sans-serif; white-space:normal; background-color:rgb(217,217,217)">                                @Override</p><p style="line-height:22px; margin-top:10px; margin-bottom:10px; font-family:Arial,Helvetica,sans-serif; white-space:normal; background-color:rgb(217,217,217)">                                public void run() {</p><p style="line-height:22px; margin-top:10px; margin-bottom:10px; font-family:Arial,Helvetica,sans-serif; white-space:normal; background-color:rgb(217,217,217)">                                    mSlideLock = false;</p><p style="line-height:22px; margin-top:10px; margin-bottom:10px; font-family:Arial,Helvetica,sans-serif; white-space:normal; background-color:rgb(217,217,217)">                                }</p><p style="line-height:22px; margin-top:10px; margin-bottom:10px; font-family:Arial,Helvetica,sans-serif; white-space:normal; background-color:rgb(217,217,217)"> </p><p style="line-height:22px; margin-top:10px; margin-bottom:10px; font-family:Arial,Helvetica,sans-serif; white-space:normal; background-color:rgb(217,217,217)">                            }, LOCK_TIME);</p><p style="line-height:22px; margin-top:10px; margin-bottom:10px; font-family:Arial,Helvetica,sans-serif; white-space:normal; background-color:rgb(217,217,217)">                        }</p><p style="line-height:22px; margin-top:10px; margin-bottom:10px; font-family:Arial,Helvetica,sans-serif; white-space:normal; background-color:rgb(217,217,217)">                    }</p><p style="line-height:22px; margin-top:10px; margin-bottom:10px; font-family:Arial,Helvetica,sans-serif; white-space:normal; background-color:rgb(217,217,217)">                }</p><p style="line-height:22px; margin-top:10px; margin-bottom:10px; font-family:Arial,Helvetica,sans-serif; white-space:normal; background-color:rgb(217,217,217)">                return false;</p><p style="line-height:22px; margin-top:10px; margin-bottom:10px; font-family:Arial,Helvetica,sans-serif; white-space:normal; background-color:rgb(217,217,217)">            }</p><p style="line-height:22px; margin-top:10px; margin-bottom:10px; font-family:Arial,Helvetica,sans-serif; white-space:normal; background-color:rgb(217,217,217)">        });</p>

3.巧用求余。此处参考如下例子。

一个示例如下http://blog.csdn.net/xiaanming/article/details/8966621

一个实现

本实现参考第三个,实现了左右循环滑动以及定时播放

<p style="line-height:22px; margin-top:10px; margin-bottom:10px; font-family:Arial,Helvetica,sans-serif; white-space:normal; background-color:rgb(217,217,217)">/**</p><p style="line-height:22px; margin-top:10px; margin-bottom:10px; font-family:Arial,Helvetica,sans-serif; white-space:normal; background-color:rgb(217,217,217)">*</p><p style="line-height:22px; margin-top:10px; margin-bottom:10px; font-family:Arial,Helvetica,sans-serif; white-space:normal; background-color:rgb(217,217,217)">* @original author xiaanming</p><p style="line-height:22px; margin-top:10px; margin-bottom:10px; font-family:Arial,Helvetica,sans-serif; white-space:normal; background-color:rgb(217,217,217)">* update by wangyun 2013/7/24</p><p style="line-height:22px; margin-top:10px; margin-bottom:10px; font-family:Arial,Helvetica,sans-serif; white-space:normal; background-color:rgb(217,217,217)">* 增加图片自动播放</p><p style="line-height:22px; margin-top:10px; margin-bottom:10px; font-family:Arial,Helvetica,sans-serif; white-space:normal; background-color:rgb(217,217,217)">* 解决图片少时崩溃的情形</p><p style="line-height:22px; margin-top:10px; margin-bottom:10px; font-family:Arial,Helvetica,sans-serif; white-space:normal; background-color:rgb(217,217,217)">* 屏蔽单张图片是的点点</p><p style="line-height:22px; margin-top:10px; margin-bottom:10px; font-family:Arial,Helvetica,sans-serif; white-space:normal; background-color:rgb(217,217,217)">* 图片为1时显示有问题</p><p style="line-height:22px; margin-top:10px; margin-bottom:10px; font-family:Arial,Helvetica,sans-serif; white-space:normal; background-color:rgb(217,217,217)">* to do:需要处理size()为0时的异常</p><p style="line-height:22px; margin-top:10px; margin-bottom:10px; font-family:Arial,Helvetica,sans-serif; white-space:normal; background-color:rgb(217,217,217)">*/</p><p style="line-height:22px; margin-top:10px; margin-bottom:10px; font-family:Arial,Helvetica,sans-serif; white-space:normal; background-color:rgb(217,217,217)"> </p><p style="line-height:22px; margin-top:10px; margin-bottom:10px; font-family:Arial,Helvetica,sans-serif; white-space:normal; background-color:rgb(217,217,217)">package com.example.viewpagerdemo;</p><p style="line-height:22px; margin-top:10px; margin-bottom:10px; font-family:Arial,Helvetica,sans-serif; white-space:normal; background-color:rgb(217,217,217)"> </p><p style="line-height:22px; margin-top:10px; margin-bottom:10px; font-family:Arial,Helvetica,sans-serif; white-space:normal; background-color:rgb(217,217,217)">import android.app.Activity;</p><p style="line-height:22px; margin-top:10px; margin-bottom:10px; font-family:Arial,Helvetica,sans-serif; white-space:normal; background-color:rgb(217,217,217)">import android.os.Bundle;</p><p style="line-height:22px; margin-top:10px; margin-bottom:10px; font-family:Arial,Helvetica,sans-serif; white-space:normal; background-color:rgb(217,217,217)">import android.os.Handler;</p><p style="line-height:22px; margin-top:10px; margin-bottom:10px; font-family:Arial,Helvetica,sans-serif; white-space:normal; background-color:rgb(217,217,217)">import android.os.Message;</p><p style="line-height:22px; margin-top:10px; margin-bottom:10px; font-family:Arial,Helvetica,sans-serif; white-space:normal; background-color:rgb(217,217,217)">import android.support.v4.view.PagerAdapter;</p><p style="line-height:22px; margin-top:10px; margin-bottom:10px; font-family:Arial,Helvetica,sans-serif; white-space:normal; background-color:rgb(217,217,217)">import android.support.v4.view.ViewPager;</p><p style="line-height:22px; margin-top:10px; margin-bottom:10px; font-family:Arial,Helvetica,sans-serif; white-space:normal; background-color:rgb(217,217,217)">import android.support.v4.view.ViewPager.OnPageChangeListener;</p><p style="line-height:22px; margin-top:10px; margin-bottom:10px; font-family:Arial,Helvetica,sans-serif; white-space:normal; background-color:rgb(217,217,217)">import android.util.Log;</p><p style="line-height:22px; margin-top:10px; margin-bottom:10px; font-family:Arial,Helvetica,sans-serif; white-space:normal; background-color:rgb(217,217,217)">import android.view.MotionEvent;</p><p style="line-height:22px; margin-top:10px; margin-bottom:10px; font-family:Arial,Helvetica,sans-serif; white-space:normal; background-color:rgb(217,217,217)">import android.view.View;</p><p style="line-height:22px; margin-top:10px; margin-bottom:10px; font-family:Arial,Helvetica,sans-serif; white-space:normal; background-color:rgb(217,217,217)">import android.view.View.OnTouchListener;</p><p style="line-height:22px; margin-top:10px; margin-bottom:10px; font-family:Arial,Helvetica,sans-serif; white-space:normal; background-color:rgb(217,217,217)">import android.view.ViewGroup;</p><p style="line-height:22px; margin-top:10px; margin-bottom:10px; font-family:Arial,Helvetica,sans-serif; white-space:normal; background-color:rgb(217,217,217)">import android.view.ViewGroup.LayoutParams;</p><p style="line-height:22px; margin-top:10px; margin-bottom:10px; font-family:Arial,Helvetica,sans-serif; white-space:normal; background-color:rgb(217,217,217)">import android.widget.ImageView;</p><p style="line-height:22px; margin-top:10px; margin-bottom:10px; font-family:Arial,Helvetica,sans-serif; white-space:normal; background-color:rgb(217,217,217)"> </p><p style="line-height:22px; margin-top:10px; margin-bottom:10px; font-family:Arial,Helvetica,sans-serif; white-space:normal; background-color:rgb(217,217,217)">public class ViewPagerDemoActivity extends Activity {</p><p style="line-height:22px; margin-top:10px; margin-bottom:10px; font-family:Arial,Helvetica,sans-serif; white-space:normal; background-color:rgb(217,217,217)">    /**</p><p style="line-height:22px; margin-top:10px; margin-bottom:10px; font-family:Arial,Helvetica,sans-serif; white-space:normal; background-color:rgb(217,217,217)">     * ViewPager</p><p style="line-height:22px; margin-top:10px; margin-bottom:10px; font-family:Arial,Helvetica,sans-serif; white-space:normal; background-color:rgb(217,217,217)">     */</p><p style="line-height:22px; margin-top:10px; margin-bottom:10px; font-family:Arial,Helvetica,sans-serif; white-space:normal; background-color:rgb(217,217,217)">    private ViewPager viewPager;</p><p style="line-height:22px; margin-top:10px; margin-bottom:10px; font-family:Arial,Helvetica,sans-serif; white-space:normal; background-color:rgb(217,217,217)"> </p><p style="line-height:22px; margin-top:10px; margin-bottom:10px; font-family:Arial,Helvetica,sans-serif; white-space:normal; background-color:rgb(217,217,217)">    /**</p><p style="line-height:22px; margin-top:10px; margin-bottom:10px; font-family:Arial,Helvetica,sans-serif; white-space:normal; background-color:rgb(217,217,217)">     * 装点点的ImageView数组</p><p style="line-height:22px; margin-top:10px; margin-bottom:10px; font-family:Arial,Helvetica,sans-serif; white-space:normal; background-color:rgb(217,217,217)">     */</p><p style="line-height:22px; margin-top:10px; margin-bottom:10px; font-family:Arial,Helvetica,sans-serif; white-space:normal; background-color:rgb(217,217,217)">    private ImageView[] tips;</p><p style="line-height:22px; margin-top:10px; margin-bottom:10px; font-family:Arial,Helvetica,sans-serif; white-space:normal; background-color:rgb(217,217,217)"> </p><p style="line-height:22px; margin-top:10px; margin-bottom:10px; font-family:Arial,Helvetica,sans-serif; white-space:normal; background-color:rgb(217,217,217)">    /**</p><p style="line-height:22px; margin-top:10px; margin-bottom:10px; font-family:Arial,Helvetica,sans-serif; white-space:normal; background-color:rgb(217,217,217)">     * 装ImageView数组</p><p style="line-height:22px; margin-top:10px; margin-bottom:10px; font-family:Arial,Helvetica,sans-serif; white-space:normal; background-color:rgb(217,217,217)">     */</p><p style="line-height:22px; margin-top:10px; margin-bottom:10px; font-family:Arial,Helvetica,sans-serif; white-space:normal; background-color:rgb(217,217,217)">    private ImageView[][] mImageViews;</p><p style="line-height:22px; margin-top:10px; margin-bottom:10px; font-family:Arial,Helvetica,sans-serif; white-space:normal; background-color:rgb(217,217,217)"> </p><p style="line-height:22px; margin-top:10px; margin-bottom:10px; font-family:Arial,Helvetica,sans-serif; white-space:normal; background-color:rgb(217,217,217)">    /**</p><p style="line-height:22px; margin-top:10px; margin-bottom:10px; font-family:Arial,Helvetica,sans-serif; white-space:normal; background-color:rgb(217,217,217)">     * 图片资源id</p><p style="line-height:22px; margin-top:10px; margin-bottom:10px; font-family:Arial,Helvetica,sans-serif; white-space:normal; background-color:rgb(217,217,217)">     */</p><p style="line-height:22px; margin-top:10px; margin-bottom:10px; font-family:Arial,Helvetica,sans-serif; white-space:normal; background-color:rgb(217,217,217)">    private int[] imgIdArray;</p><p style="line-height:22px; margin-top:10px; margin-bottom:10px; font-family:Arial,Helvetica,sans-serif; white-space:normal; background-color:rgb(217,217,217)"> </p><p style="line-height:22px; margin-top:10px; margin-bottom:10px; font-family:Arial,Helvetica,sans-serif; white-space:normal; background-color:rgb(217,217,217)">    private static final int MSG_CHANGE_PHOTO = 1;</p><p style="line-height:22px; margin-top:10px; margin-bottom:10px; font-family:Arial,Helvetica,sans-serif; white-space:normal; background-color:rgb(217,217,217)"> </p><p style="line-height:22px; margin-top:10px; margin-bottom:10px; font-family:Arial,Helvetica,sans-serif; white-space:normal; background-color:rgb(217,217,217)">    /** 图片自动切换时间 */</p><p style="line-height:22px; margin-top:10px; margin-bottom:10px; font-family:Arial,Helvetica,sans-serif; white-space:normal; background-color:rgb(217,217,217)">    private static final int PHOTO_CHANGE_TIME = 5000;</p><p style="line-height:22px; margin-top:10px; margin-bottom:10px; font-family:Arial,Helvetica,sans-serif; white-space:normal; background-color:rgb(217,217,217)">    private Handler mHandler = new Handler() {</p><p style="line-height:22px; margin-top:10px; margin-bottom:10px; font-family:Arial,Helvetica,sans-serif; white-space:normal; background-color:rgb(217,217,217)">        @Override</p><p style="line-height:22px; margin-top:10px; margin-bottom:10px; font-family:Arial,Helvetica,sans-serif; white-space:normal; background-color:rgb(217,217,217)">        public void dispatchMessage(Message msg) {</p><p style="line-height:22px; margin-top:10px; margin-bottom:10px; font-family:Arial,Helvetica,sans-serif; white-space:normal; background-color:rgb(217,217,217)">            switch (msg.what) {</p><p style="line-height:22px; margin-top:10px; margin-bottom:10px; font-family:Arial,Helvetica,sans-serif; white-space:normal; background-color:rgb(217,217,217)">            case MSG_CHANGE_PHOTO:</p><p style="line-height:22px; margin-top:10px; margin-bottom:10px; font-family:Arial,Helvetica,sans-serif; white-space:normal; background-color:rgb(217,217,217)">                int index = viewPager.getCurrentItem();</p><p style="line-height:22px; margin-top:10px; margin-bottom:10px; font-family:Arial,Helvetica,sans-serif; white-space:normal; background-color:rgb(217,217,217)">                viewPager.setCurrentItem(index + 1);</p><p style="line-height:22px; margin-top:10px; margin-bottom:10px; font-family:Arial,Helvetica,sans-serif; white-space:normal; background-color:rgb(217,217,217)">                mHandler.sendEmptyMessageDelayed(MSG_CHANGE_PHOTO,</p><p style="line-height:22px; margin-top:10px; margin-bottom:10px; font-family:Arial,Helvetica,sans-serif; white-space:normal; background-color:rgb(217,217,217)">                        PHOTO_CHANGE_TIME);</p><p style="line-height:22px; margin-top:10px; margin-bottom:10px; font-family:Arial,Helvetica,sans-serif; white-space:normal; background-color:rgb(217,217,217)">                break;</p><p style="line-height:22px; margin-top:10px; margin-bottom:10px; font-family:Arial,Helvetica,sans-serif; white-space:normal; background-color:rgb(217,217,217)">            }</p><p style="line-height:22px; margin-top:10px; margin-bottom:10px; font-family:Arial,Helvetica,sans-serif; white-space:normal; background-color:rgb(217,217,217)">            super.dispatchMessage(msg);</p><p style="line-height:22px; margin-top:10px; margin-bottom:10px; font-family:Arial,Helvetica,sans-serif; white-space:normal; background-color:rgb(217,217,217)">        }</p><p style="line-height:22px; margin-top:10px; margin-bottom:10px; font-family:Arial,Helvetica,sans-serif; white-space:normal; background-color:rgb(217,217,217)">    };</p><p style="line-height:22px; margin-top:10px; margin-bottom:10px; font-family:Arial,Helvetica,sans-serif; white-space:normal; background-color:rgb(217,217,217)"> </p><p style="line-height:22px; margin-top:10px; margin-bottom:10px; font-family:Arial,Helvetica,sans-serif; white-space:normal; background-color:rgb(217,217,217)">    @Override</p><p style="line-height:22px; margin-top:10px; margin-bottom:10px; font-family:Arial,Helvetica,sans-serif; white-space:normal; background-color:rgb(217,217,217)">    protected void onCreate(Bundle savedInstanceState) {</p><p style="line-height:22px; margin-top:10px; margin-bottom:10px; font-family:Arial,Helvetica,sans-serif; white-space:normal; background-color:rgb(217,217,217)">        super.onCreate(savedInstanceState);</p><p style="line-height:22px; margin-top:10px; margin-bottom:10px; font-family:Arial,Helvetica,sans-serif; white-space:normal; background-color:rgb(217,217,217)">        setContentView(R.layout.activity_main);</p><p style="line-height:22px; margin-top:10px; margin-bottom:10px; font-family:Arial,Helvetica,sans-serif; white-space:normal; background-color:rgb(217,217,217)">        ViewGroup group = (ViewGroup) findViewById(R.id.viewGroup);</p><p style="line-height:22px; margin-top:10px; margin-bottom:10px; font-family:Arial,Helvetica,sans-serif; white-space:normal; background-color:rgb(217,217,217)">        viewPager = (ViewPager) findViewById(R.id.viewPager);</p><p style="line-height:22px; margin-top:10px; margin-bottom:10px; font-family:Arial,Helvetica,sans-serif; white-space:normal; background-color:rgb(217,217,217)"> </p><p style="line-height:22px; margin-top:10px; margin-bottom:10px; font-family:Arial,Helvetica,sans-serif; white-space:normal; background-color:rgb(217,217,217)"> </p><p style="line-height:22px; margin-top:10px; margin-bottom:10px; font-family:Arial,Helvetica,sans-serif; white-space:normal; background-color:rgb(217,217,217)">        // 载入图片资源ID</p><p style="line-height:22px; margin-top:10px; margin-bottom:10px; font-family:Arial,Helvetica,sans-serif; white-space:normal; background-color:rgb(217,217,217)">        imgIdArray = new int[] { R.drawable.item1 ,R.drawable.item2,R.drawable.item3,R.drawable.item4,R.drawable.item5};</p><p style="line-height:22px; margin-top:10px; margin-bottom:10px; font-family:Arial,Helvetica,sans-serif; white-space:normal; background-color:rgb(217,217,217)"> </p><p style="line-height:22px; margin-top:10px; margin-bottom:10px; font-family:Arial,Helvetica,sans-serif; white-space:normal; background-color:rgb(217,217,217)">        // 将点点加入到ViewGroup中</p><p style="line-height:22px; margin-top:10px; margin-bottom:10px; font-family:Arial,Helvetica,sans-serif; white-space:normal; background-color:rgb(217,217,217)">        tips = new ImageView[imgIdArray.length];</p><p style="line-height:22px; margin-top:10px; margin-bottom:10px; font-family:Arial,Helvetica,sans-serif; white-space:normal; background-color:rgb(217,217,217)"> </p><p style="line-height:22px; margin-top:10px; margin-bottom:10px; font-family:Arial,Helvetica,sans-serif; white-space:normal; background-color:rgb(217,217,217)">        if (imgIdArray.length <= 1)</p><p style="line-height:22px; margin-top:10px; margin-bottom:10px; font-family:Arial,Helvetica,sans-serif; white-space:normal; background-color:rgb(217,217,217)">            group.setVisibility(View.GONE);</p><p style="line-height:22px; margin-top:10px; margin-bottom:10px; font-family:Arial,Helvetica,sans-serif; white-space:normal; background-color:rgb(217,217,217)">        for (int i = 0; i < tips.length; i++) {</p><p style="line-height:22px; margin-top:10px; margin-bottom:10px; font-family:Arial,Helvetica,sans-serif; white-space:normal; background-color:rgb(217,217,217)">            ImageView imageView = new ImageView(this);</p><p style="line-height:22px; margin-top:10px; margin-bottom:10px; font-family:Arial,Helvetica,sans-serif; white-space:normal; background-color:rgb(217,217,217)">            imageView.setLayoutParams(new LayoutParams(10, 10));</p><p style="line-height:22px; margin-top:10px; margin-bottom:10px; font-family:Arial,Helvetica,sans-serif; white-space:normal; background-color:rgb(217,217,217)">            tips[i] = imageView;</p><p style="line-height:22px; margin-top:10px; margin-bottom:10px; font-family:Arial,Helvetica,sans-serif; white-space:normal; background-color:rgb(217,217,217)">            if (i == 0) {</p><p style="line-height:22px; margin-top:10px; margin-bottom:10px; font-family:Arial,Helvetica,sans-serif; white-space:normal; background-color:rgb(217,217,217)">                tips[i].setBackgroundResource(R.drawable.page_indicator_focused);</p><p style="line-height:22px; margin-top:10px; margin-bottom:10px; font-family:Arial,Helvetica,sans-serif; white-space:normal; background-color:rgb(217,217,217)">            } else {</p><p style="line-height:22px; margin-top:10px; margin-bottom:10px; font-family:Arial,Helvetica,sans-serif; white-space:normal; background-color:rgb(217,217,217)">                tips[i].setBackgroundResource(R.drawable.page_indicator_unfocused);</p><p style="line-height:22px; margin-top:10px; margin-bottom:10px; font-family:Arial,Helvetica,sans-serif; white-space:normal; background-color:rgb(217,217,217)">            }</p><p style="line-height:22px; margin-top:10px; margin-bottom:10px; font-family:Arial,Helvetica,sans-serif; white-space:normal; background-color:rgb(217,217,217)"> </p><p style="line-height:22px; margin-top:10px; margin-bottom:10px; font-family:Arial,Helvetica,sans-serif; white-space:normal; background-color:rgb(217,217,217)">            group.addView(imageView);</p><p style="line-height:22px; margin-top:10px; margin-bottom:10px; font-family:Arial,Helvetica,sans-serif; white-space:normal; background-color:rgb(217,217,217)">        }</p><p style="line-height:22px; margin-top:10px; margin-bottom:10px; font-family:Arial,Helvetica,sans-serif; white-space:normal; background-color:rgb(217,217,217)"> </p><p style="line-height:22px; margin-top:10px; margin-bottom:10px; font-family:Arial,Helvetica,sans-serif; white-space:normal; background-color:rgb(217,217,217)">        mImageViews = new ImageView[2][];</p><p style="line-height:22px; margin-top:10px; margin-bottom:10px; font-family:Arial,Helvetica,sans-serif; white-space:normal; background-color:rgb(217,217,217)">        // 将图片装载到数组中,其中一组类似缓冲,防止图片少时出现黑色图片,即显示不出来</p><p style="line-height:22px; margin-top:10px; margin-bottom:10px; font-family:Arial,Helvetica,sans-serif; white-space:normal; background-color:rgb(217,217,217)">        mImageViews[0] = new ImageView[imgIdArray.length];</p><p style="line-height:22px; margin-top:10px; margin-bottom:10px; font-family:Arial,Helvetica,sans-serif; white-space:normal; background-color:rgb(217,217,217)">        mImageViews[1] = new ImageView[imgIdArray.length];</p><p style="line-height:22px; margin-top:10px; margin-bottom:10px; font-family:Arial,Helvetica,sans-serif; white-space:normal; background-color:rgb(217,217,217)"> </p><p style="line-height:22px; margin-top:10px; margin-bottom:10px; font-family:Arial,Helvetica,sans-serif; white-space:normal; background-color:rgb(217,217,217)">        for (int i = 0; i < mImageViews.length; i++) {</p><p style="line-height:22px; margin-top:10px; margin-bottom:10px; font-family:Arial,Helvetica,sans-serif; white-space:normal; background-color:rgb(217,217,217)">            for (int j = 0; j < mImageViews[i].length; j++) {</p><p style="line-height:22px; margin-top:10px; margin-bottom:10px; font-family:Arial,Helvetica,sans-serif; white-space:normal; background-color:rgb(217,217,217)">                ImageView imageView = new ImageView(this);</p><p style="line-height:22px; margin-top:10px; margin-bottom:10px; font-family:Arial,Helvetica,sans-serif; white-space:normal; background-color:rgb(217,217,217)">                imageView.setBackgroundResource(imgIdArray[j]);</p><p style="line-height:22px; margin-top:10px; margin-bottom:10px; font-family:Arial,Helvetica,sans-serif; white-space:normal; background-color:rgb(217,217,217)">                mImageViews[i][j] = imageView;</p><p style="line-height:22px; margin-top:10px; margin-bottom:10px; font-family:Arial,Helvetica,sans-serif; white-space:normal; background-color:rgb(217,217,217)">                Log.i("TwoActivity_WY", i + "," + j + "\t");</p><p style="line-height:22px; margin-top:10px; margin-bottom:10px; font-family:Arial,Helvetica,sans-serif; white-space:normal; background-color:rgb(217,217,217)">            }</p><p style="line-height:22px; margin-top:10px; margin-bottom:10px; font-family:Arial,Helvetica,sans-serif; white-space:normal; background-color:rgb(217,217,217)">        }</p><p style="line-height:22px; margin-top:10px; margin-bottom:10px; font-family:Arial,Helvetica,sans-serif; white-space:normal; background-color:rgb(217,217,217)"> </p><p style="line-height:22px; margin-top:10px; margin-bottom:10px; font-family:Arial,Helvetica,sans-serif; white-space:normal; background-color:rgb(217,217,217)">        // 设置Adapter</p><p style="line-height:22px; margin-top:10px; margin-bottom:10px; font-family:Arial,Helvetica,sans-serif; white-space:normal; background-color:rgb(217,217,217)">        viewPager.setAdapter(new MyAdapter());</p><p style="line-height:22px; margin-top:10px; margin-bottom:10px; font-family:Arial,Helvetica,sans-serif; white-space:normal; background-color:rgb(217,217,217)">        // 设置监听,主要是设置点点的背景</p><p style="line-height:22px; margin-top:10px; margin-bottom:10px; font-family:Arial,Helvetica,sans-serif; white-space:normal; background-color:rgb(217,217,217)">        viewPager.setOnPageChangeListener(new OnPageChangeListener() {</p><p style="line-height:22px; margin-top:10px; margin-bottom:10px; font-family:Arial,Helvetica,sans-serif; white-space:normal; background-color:rgb(217,217,217)">            </p><p style="line-height:22px; margin-top:10px; margin-bottom:10px; font-family:Arial,Helvetica,sans-serif; white-space:normal; background-color:rgb(217,217,217)">            @Override</p><p style="line-height:22px; margin-top:10px; margin-bottom:10px; font-family:Arial,Helvetica,sans-serif; white-space:normal; background-color:rgb(217,217,217)">            public void onPageScrollStateChanged(int arg0) {</p><p style="line-height:22px; margin-top:10px; margin-bottom:10px; font-family:Arial,Helvetica,sans-serif; white-space:normal; background-color:rgb(217,217,217)"> </p><p style="line-height:22px; margin-top:10px; margin-bottom:10px; font-family:Arial,Helvetica,sans-serif; white-space:normal; background-color:rgb(217,217,217)">            }</p><p style="line-height:22px; margin-top:10px; margin-bottom:10px; font-family:Arial,Helvetica,sans-serif; white-space:normal; background-color:rgb(217,217,217)"> </p><p style="line-height:22px; margin-top:10px; margin-bottom:10px; font-family:Arial,Helvetica,sans-serif; white-space:normal; background-color:rgb(217,217,217)">            @Override</p><p style="line-height:22px; margin-top:10px; margin-bottom:10px; font-family:Arial,Helvetica,sans-serif; white-space:normal; background-color:rgb(217,217,217)">            public void onPageScrolled(int arg0, float arg1, int arg2) {</p><p style="line-height:22px; margin-top:10px; margin-bottom:10px; font-family:Arial,Helvetica,sans-serif; white-space:normal; background-color:rgb(217,217,217)"> </p><p style="line-height:22px; margin-top:10px; margin-bottom:10px; font-family:Arial,Helvetica,sans-serif; white-space:normal; background-color:rgb(217,217,217)">            }</p><p style="line-height:22px; margin-top:10px; margin-bottom:10px; font-family:Arial,Helvetica,sans-serif; white-space:normal; background-color:rgb(217,217,217)"> </p><p style="line-height:22px; margin-top:10px; margin-bottom:10px; font-family:Arial,Helvetica,sans-serif; white-space:normal; background-color:rgb(217,217,217)">            @Override</p><p style="line-height:22px; margin-top:10px; margin-bottom:10px; font-family:Arial,Helvetica,sans-serif; white-space:normal; background-color:rgb(217,217,217)">            public void onPageSelected(int arg0) {</p><p style="line-height:22px; margin-top:10px; margin-bottom:10px; font-family:Arial,Helvetica,sans-serif; white-space:normal; background-color:rgb(217,217,217)">                setImageBackground(arg0 % imgIdArray.length);</p><p style="line-height:22px; margin-top:10px; margin-bottom:10px; font-family:Arial,Helvetica,sans-serif; white-space:normal; background-color:rgb(217,217,217)">            }</p><p style="line-height:22px; margin-top:10px; margin-bottom:10px; font-family:Arial,Helvetica,sans-serif; white-space:normal; background-color:rgb(217,217,217)">        });</p><p style="line-height:22px; margin-top:10px; margin-bottom:10px; font-family:Arial,Helvetica,sans-serif; white-space:normal; background-color:rgb(217,217,217)">        </p><p style="line-height:22px; margin-top:10px; margin-bottom:10px; font-family:Arial,Helvetica,sans-serif; white-space:normal; background-color:rgb(217,217,217)">        viewPager.setOnTouchListener(new OnTouchListener() {</p><p style="line-height:22px; margin-top:10px; margin-bottom:10px; font-family:Arial,Helvetica,sans-serif; white-space:normal; background-color:rgb(217,217,217)">            </p><p style="line-height:22px; margin-top:10px; margin-bottom:10px; font-family:Arial,Helvetica,sans-serif; white-space:normal; background-color:rgb(217,217,217)">            @Override</p><p style="line-height:22px; margin-top:10px; margin-bottom:10px; font-family:Arial,Helvetica,sans-serif; white-space:normal; background-color:rgb(217,217,217)">            public boolean onTouch(View v, MotionEvent event) {</p><p style="line-height:22px; margin-top:10px; margin-bottom:10px; font-family:Arial,Helvetica,sans-serif; white-space:normal; background-color:rgb(217,217,217)">                if(imgIdArray.length==0||imgIdArray.length==1)</p><p style="line-height:22px; margin-top:10px; margin-bottom:10px; font-family:Arial,Helvetica,sans-serif; white-space:normal; background-color:rgb(217,217,217)">                    return true;</p><p style="line-height:22px; margin-top:10px; margin-bottom:10px; font-family:Arial,Helvetica,sans-serif; white-space:normal; background-color:rgb(217,217,217)">                else</p><p style="line-height:22px; margin-top:10px; margin-bottom:10px; font-family:Arial,Helvetica,sans-serif; white-space:normal; background-color:rgb(217,217,217)">                    return false;</p><p style="line-height:22px; margin-top:10px; margin-bottom:10px; font-family:Arial,Helvetica,sans-serif; white-space:normal; background-color:rgb(217,217,217)">            }</p><p style="line-height:22px; margin-top:10px; margin-bottom:10px; font-family:Arial,Helvetica,sans-serif; white-space:normal; background-color:rgb(217,217,217)">        });</p><p style="line-height:22px; margin-top:10px; margin-bottom:10px; font-family:Arial,Helvetica,sans-serif; white-space:normal; background-color:rgb(217,217,217)"> </p><p style="line-height:22px; margin-top:10px; margin-bottom:10px; font-family:Arial,Helvetica,sans-serif; white-space:normal; background-color:rgb(217,217,217)">        // 设置ViewPager的默认项, 设置为长度的50倍,这样子开始就能往左滑动</p><p style="line-height:22px; margin-top:10px; margin-bottom:10px; font-family:Arial,Helvetica,sans-serif; white-space:normal; background-color:rgb(217,217,217)">        viewPager.setCurrentItem((imgIdArray.length) * 50);</p><p style="line-height:22px; margin-top:10px; margin-bottom:10px; font-family:Arial,Helvetica,sans-serif; white-space:normal; background-color:rgb(217,217,217)">        mHandler.sendEmptyMessageDelayed(MSG_CHANGE_PHOTO, PHOTO_CHANGE_TIME);</p><p style="line-height:22px; margin-top:10px; margin-bottom:10px; font-family:Arial,Helvetica,sans-serif; white-space:normal; background-color:rgb(217,217,217)">    }</p><p style="line-height:22px; margin-top:10px; margin-bottom:10px; font-family:Arial,Helvetica,sans-serif; white-space:normal; background-color:rgb(217,217,217)"> </p><p style="line-height:22px; margin-top:10px; margin-bottom:10px; font-family:Arial,Helvetica,sans-serif; white-space:normal; background-color:rgb(217,217,217)">    public class MyAdapter extends PagerAdapter {</p><p style="line-height:22px; margin-top:10px; margin-bottom:10px; font-family:Arial,Helvetica,sans-serif; white-space:normal; background-color:rgb(217,217,217)"> </p><p style="line-height:22px; margin-top:10px; margin-bottom:10px; font-family:Arial,Helvetica,sans-serif; white-space:normal; background-color:rgb(217,217,217)">        @Override</p><p style="line-height:22px; margin-top:10px; margin-bottom:10px; font-family:Arial,Helvetica,sans-serif; white-space:normal; background-color:rgb(217,217,217)">        public int getCount() {</p><p style="line-height:22px; margin-top:10px; margin-bottom:10px; font-family:Arial,Helvetica,sans-serif; white-space:normal; background-color:rgb(217,217,217)">            return Integer.MAX_VALUE;</p><p style="line-height:22px; margin-top:10px; margin-bottom:10px; font-family:Arial,Helvetica,sans-serif; white-space:normal; background-color:rgb(217,217,217)">        }</p><p style="line-height:22px; margin-top:10px; margin-bottom:10px; font-family:Arial,Helvetica,sans-serif; white-space:normal; background-color:rgb(217,217,217)"> </p><p style="line-height:22px; margin-top:10px; margin-bottom:10px; font-family:Arial,Helvetica,sans-serif; white-space:normal; background-color:rgb(217,217,217)">        @Override</p><p style="line-height:22px; margin-top:10px; margin-bottom:10px; font-family:Arial,Helvetica,sans-serif; white-space:normal; background-color:rgb(217,217,217)">        public boolean isViewFromObject(View arg0, Object arg1) {</p><p style="line-height:22px; margin-top:10px; margin-bottom:10px; font-family:Arial,Helvetica,sans-serif; white-space:normal; background-color:rgb(217,217,217)">            return arg0 == arg1;</p><p style="line-height:22px; margin-top:10px; margin-bottom:10px; font-family:Arial,Helvetica,sans-serif; white-space:normal; background-color:rgb(217,217,217)">        }</p><p style="line-height:22px; margin-top:10px; margin-bottom:10px; font-family:Arial,Helvetica,sans-serif; white-space:normal; background-color:rgb(217,217,217)"> </p><p style="line-height:22px; margin-top:10px; margin-bottom:10px; font-family:Arial,Helvetica,sans-serif; white-space:normal; background-color:rgb(217,217,217)">        @Override</p><p style="line-height:22px; margin-top:10px; margin-bottom:10px; font-family:Arial,Helvetica,sans-serif; white-space:normal; background-color:rgb(217,217,217)">        public void destroyItem(View container, int position, Object object) {</p><p style="line-height:22px; margin-top:10px; margin-bottom:10px; font-family:Arial,Helvetica,sans-serif; white-space:normal; background-color:rgb(217,217,217)">            if (imgIdArray.length == 1)</p><p style="line-height:22px; margin-top:10px; margin-bottom:10px; font-family:Arial,Helvetica,sans-serif; white-space:normal; background-color:rgb(217,217,217)">                ((ViewPager) container).removeView(mImageViews[position</p><p style="line-height:22px; margin-top:10px; margin-bottom:10px; font-family:Arial,Helvetica,sans-serif; white-space:normal; background-color:rgb(217,217,217)">                        / imgIdArray.length % 2][0]);</p><p style="line-height:22px; margin-top:10px; margin-bottom:10px; font-family:Arial,Helvetica,sans-serif; white-space:normal; background-color:rgb(217,217,217)">            else</p><p style="line-height:22px; margin-top:10px; margin-bottom:10px; font-family:Arial,Helvetica,sans-serif; white-space:normal; background-color:rgb(217,217,217)">                ((ViewPager) container).removeView(mImageViews[position</p><p style="line-height:22px; margin-top:10px; margin-bottom:10px; font-family:Arial,Helvetica,sans-serif; white-space:normal; background-color:rgb(217,217,217)">                        / imgIdArray.length % 2][position % imgIdArray.length]);</p><p style="line-height:22px; margin-top:10px; margin-bottom:10px; font-family:Arial,Helvetica,sans-serif; white-space:normal; background-color:rgb(217,217,217)">        }</p><p style="line-height:22px; margin-top:10px; margin-bottom:10px; font-family:Arial,Helvetica,sans-serif; white-space:normal; background-color:rgb(217,217,217)"> </p><p style="line-height:22px; margin-top:10px; margin-bottom:10px; font-family:Arial,Helvetica,sans-serif; white-space:normal; background-color:rgb(217,217,217)">        /**</p><p style="line-height:22px; margin-top:10px; margin-bottom:10px; font-family:Arial,Helvetica,sans-serif; white-space:normal; background-color:rgb(217,217,217)">         * 载入图片进去,用当前的position 除以 图片数组长度取余数是关键</p><p style="line-height:22px; margin-top:10px; margin-bottom:10px; font-family:Arial,Helvetica,sans-serif; white-space:normal; background-color:rgb(217,217,217)">         */</p><p style="line-height:22px; margin-top:10px; margin-bottom:10px; font-family:Arial,Helvetica,sans-serif; white-space:normal; background-color:rgb(217,217,217)">        @Override</p><p style="line-height:22px; margin-top:10px; margin-bottom:10px; font-family:Arial,Helvetica,sans-serif; white-space:normal; background-color:rgb(217,217,217)">        public Object instantiateItem(View container, int position) {</p><p style="line-height:22px; margin-top:10px; margin-bottom:10px; font-family:Arial,Helvetica,sans-serif; white-space:normal; background-color:rgb(217,217,217)">            if (imgIdArray.length == 1)</p><p style="line-height:22px; margin-top:10px; margin-bottom:10px; font-family:Arial,Helvetica,sans-serif; white-space:normal; background-color:rgb(217,217,217)">                return mImageViews[position / imgIdArray.length % 2][0];</p><p style="line-height:22px; margin-top:10px; margin-bottom:10px; font-family:Arial,Helvetica,sans-serif; white-space:normal; background-color:rgb(217,217,217)">            else</p><p style="line-height:22px; margin-top:10px; margin-bottom:10px; font-family:Arial,Helvetica,sans-serif; white-space:normal; background-color:rgb(217,217,217)">                ((ViewPager) container).addView(mImageViews[position</p><p style="line-height:22px; margin-top:10px; margin-bottom:10px; font-family:Arial,Helvetica,sans-serif; white-space:normal; background-color:rgb(217,217,217)">                        / imgIdArray.length % 2][position % imgIdArray.length],</p><p style="line-height:22px; margin-top:10px; margin-bottom:10px; font-family:Arial,Helvetica,sans-serif; white-space:normal; background-color:rgb(217,217,217)">                        0);</p><p style="line-height:22px; margin-top:10px; margin-bottom:10px; font-family:Arial,Helvetica,sans-serif; white-space:normal; background-color:rgb(217,217,217)">            return mImageViews[position / imgIdArray.length % 2][position</p><p style="line-height:22px; margin-top:10px; margin-bottom:10px; font-family:Arial,Helvetica,sans-serif; white-space:normal; background-color:rgb(217,217,217)">                    % imgIdArray.length];</p><p style="line-height:22px; margin-top:10px; margin-bottom:10px; font-family:Arial,Helvetica,sans-serif; white-space:normal; background-color:rgb(217,217,217)">        }</p><p style="line-height:22px; margin-top:10px; margin-bottom:10px; font-family:Arial,Helvetica,sans-serif; white-space:normal; background-color:rgb(217,217,217)"> </p><p style="line-height:22px; margin-top:10px; margin-bottom:10px; font-family:Arial,Helvetica,sans-serif; white-space:normal; background-color:rgb(217,217,217)">    }</p><p style="line-height:22px; margin-top:10px; margin-bottom:10px; font-family:Arial,Helvetica,sans-serif; white-space:normal; background-color:rgb(217,217,217)"> </p><p style="line-height:22px; margin-top:10px; margin-bottom:10px; font-family:Arial,Helvetica,sans-serif; white-space:normal; background-color:rgb(217,217,217)"> </p><p style="line-height:22px; margin-top:10px; margin-bottom:10px; font-family:Arial,Helvetica,sans-serif; white-space:normal; background-color:rgb(217,217,217)"> </p><p style="line-height:22px; margin-top:10px; margin-bottom:10px; font-family:Arial,Helvetica,sans-serif; white-space:normal; background-color:rgb(217,217,217)">    /**</p><p style="line-height:22px; margin-top:10px; margin-bottom:10px; font-family:Arial,Helvetica,sans-serif; white-space:normal; background-color:rgb(217,217,217)">     * 设置选中的tip的背景</p><p style="line-height:22px; margin-top:10px; margin-bottom:10px; font-family:Arial,Helvetica,sans-serif; white-space:normal; background-color:rgb(217,217,217)">     *</p><p style="line-height:22px; margin-top:10px; margin-bottom:10px; font-family:Arial,Helvetica,sans-serif; white-space:normal; background-color:rgb(217,217,217)">     * @param selectItemsIndex</p><p style="line-height:22px; margin-top:10px; margin-bottom:10px; font-family:Arial,Helvetica,sans-serif; white-space:normal; background-color:rgb(217,217,217)">     */</p><p style="line-height:22px; margin-top:10px; margin-bottom:10px; font-family:Arial,Helvetica,sans-serif; white-space:normal; background-color:rgb(217,217,217)">    private void setImageBackground(int selectItemsIndex) {</p><p style="line-height:22px; margin-top:10px; margin-bottom:10px; font-family:Arial,Helvetica,sans-serif; white-space:normal; background-color:rgb(217,217,217)">        for (int i = 0; i < tips.length; i++) {</p><p style="line-height:22px; margin-top:10px; margin-bottom:10px; font-family:Arial,Helvetica,sans-serif; white-space:normal; background-color:rgb(217,217,217)">            if (i == selectItemsIndex) {</p><p style="line-height:22px; margin-top:10px; margin-bottom:10px; font-family:Arial,Helvetica,sans-serif; white-space:normal; background-color:rgb(217,217,217)">                tips[i].setBackgroundResource(R.drawable.page_indicator_focused);</p><p style="line-height:22px; margin-top:10px; margin-bottom:10px; font-family:Arial,Helvetica,sans-serif; white-space:normal; background-color:rgb(217,217,217)">            } else {</p><p style="line-height:22px; margin-top:10px; margin-bottom:10px; font-family:Arial,Helvetica,sans-serif; white-space:normal; background-color:rgb(217,217,217)">                tips[i].setBackgroundResource(R.drawable.page_indicator_unfocused);</p><p style="line-height:22px; margin-top:10px; margin-bottom:10px; font-family:Arial,Helvetica,sans-serif; white-space:normal; background-color:rgb(217,217,217)">            }</p><p style="line-height:22px; margin-top:10px; margin-bottom:10px; font-family:Arial,Helvetica,sans-serif; white-space:normal; background-color:rgb(217,217,217)">        }</p><p style="line-height:22px; margin-top:10px; margin-bottom:10px; font-family:Arial,Helvetica,sans-serif; white-space:normal; background-color:rgb(217,217,217)">    }</p><p style="line-height:22px; margin-top:10px; margin-bottom:10px; font-family:Arial,Helvetica,sans-serif; white-space:normal; background-color:rgb(217,217,217)"> </p><p style="line-height:22px; margin-top:10px; margin-bottom:10px; font-family:Arial,Helvetica,sans-serif; white-space:normal; background-color:rgb(217,217,217)">}</p>

下载地址

即得

文档下载地址


以下是一位网友封装的一个ViewPager库,实现了我说的基本所有的功能
http://download.csdn.net/detail/waylife/6197781
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值