vp_viewpager.setOnPageChangeListener(new OnPageChangeListener() {-------------------------------------MainActivity.java
@Override
public void onPageSelected(int position) {
for (int i = 0; i < icons.length; i++) {
// 循环将所有的指示性图标全部置为未选中
icons[i].setEnabled(true);
}
// 将page对应的指示性图标置为选中
icons[position%imageViewList.size()].setEnabled(false);
index = position;
}
@Override
public void onPageScrolled(int arg0, float arg1, int arg2) {
vp_viewpager.getParent().requestDisallowInterceptTouchEvent(true);
}
@Override
public void onPageScrollStateChanged(int arg0) {
}
});
vp_viewpager.setOnTouchListener(new View.OnTouchListener() {
@Override
public boolean onTouch(View v, MotionEvent event) {
v.getParent().requestDisallowInterceptTouchEvent(true);
return false;
}
});
===================================================================================================================================
package com.alice.asaproject.adpter;----------------------------------------------------------------------PagerAdapter的适配器
import java.util.List;
import android.os.Bundle;
import android.support.v4.view.PagerAdapter;
import android.support.v4.view.ViewPager;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
public class MyPagerAdapter extends PagerAdapter {
private List<ImageView> imageViewList = null;
public MyPagerAdapter(List<ImageView> imageViewList) {
this.imageViewList = imageViewList;
}
@Override
public int getCount() {
return Integer.MAX_VALUE;
}
@Override
public boolean isViewFromObject(View arg0, Object arg1) {
return arg0 == arg1;
}
@Override
public Object instantiateItem(ViewGroup container, int position) {
View view = imageViewList.get(position % imageViewList.size());
((ViewPager)container).addView(view, 0); //设置手动在Viewpager的最后一页滑到第一页
return view;
}
@Override
public void destroyItem(ViewGroup container, int position, Object object) {
((ViewPager)container).removeView(imageViewList.get(position % imageViewList.size()));
} //设置手动在Viewpager的最后一页滑到第一页
// protected void onCreate(Bundle savedInstanceState) {
// vp_viewpager.setAdapter(new MyPagerAdapter( imageViewList,vp_viewpager));
// //设置ViewPager的默认项, 设置为总数的100倍,一开始才能往左滑动
// vp_viewpager.setCurrentItem(imageViewList.size() * 100);
// }
}