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;
}
});
@Override
public Object instantiateItem(ViewGroup container, int position) {
// TODO Auto-generated method stub
position %= imageViewList.size();
if (position < 0) {
position = imageViewList.size() + position;
}
ImageView view = imageViewList.get(position);
// 如果View已经在之前添加到了一个父组件,则必须先remove,否则会抛出IllegalStateException。
ViewParent vp = view.getParent();
if (vp != null) {
ViewGroup parent = (ViewGroup) vp;
parent.removeView(view);
}
container.addView(view);
// View view = imageViewList.get(position % imageViewList.size());
// ((ViewPager)container).addView(view, 0);
return view;