设置自动轮播的小圆点
private void initDot() {
listIV = new ArrayList<>();
if (listIV !=null){
listIV.clear();
}
for (int x =0;
xImageView iv = new ImageView(MainActivity.this);
if (x==0){
iv.setImageResource(R.drawable.dot_focus);
}else{
iv.setImageResource(R.drawable.dot_normal);
}
listIV.add(iv);
LinearLayout.LayoutParams params = new LinearLayout.LayoutParams(20,20);
params.setMargins(10,0,10,0);
ll.addView(iv,params);
}
ViewPager.addOnPageChangeListener(new ViewPager.OnPageChangeListener() { @Override public void onPageScrolled(int position, float positionOffset, int positionOffsetPixels) { } @Override public void onPageSelected(int position) { for (int x = 0; x < imageViews.size(); x++) { if (position % listbean.size() == x) { imageViews.get(position % listbean.size()).setImageResource(R.drawable.dot_focus); } else { imageViews.get(x).setImageResource(R.drawable.dot_normal); } }} @Override public void onPageScrollStateChanged(int state) { } });
【设置自动轮播的小圆点】在res\drawable创建file文件.xml
dot_normal.xml
dot_focus.xml