ViewPager适配器

//设置viewPager
private void initViewPager() {
pageAdapter = new ViewPageAdapter(getActivity(),pageList);
viewPager.setAdapter(pageAdapter);
handler.sendEmptyMessageDelayed(0,2000);
viewPager.setCurrentItem(pageList.size()*10000);

init();

viewPager.addOnPageChangeListener(new ViewPager.OnPageChangeListener() {
@Override
public void onPageScrolled(int position, float positionOffset, int positionOffsetPixels) {

}

@Override
public void onPageSelected(int position) {
for (int i = 0; i < imageList.size(); i++) {
if (position % imageList.size() == i) {
imageList.get(i).setImageResource(R.drawable.shape_checked);
} else {
imageList.get(i).setImageResource(R.drawable.shape_normal);
}
}
}

@Override
public void onPageScrollStateChanged(int state) {

}
});
}
//设置图片小圆点
private void init() {
imageList = new ArrayList();

layout.removeAllViews();
imageList.clear();
for (int i = 0; i < 3; i++) {
ImageView image=new ImageView(getActivity());
if (i==0){
image.setImageResource(R.drawable.shape_checked);
}else {
image.setImageResource(R.drawable.shape_normal);
}

LinearLayout.LayoutParams params=new LinearLayout.LayoutParams(LinearLayout.LayoutParams.WRAP_CONTENT, LinearLayout.LayoutParams.WRAP_CONTENT);
params.setMargins(5,0,5,0);
layout.addView(image,params);
imageList.add(image);
}
}

你可能感兴趣的:(ViewPager适配器)