private Handler handler = new Handler() { @Override public void handleMessage(Message msg) { //获取viewpager的最大数 int currentItem = vp_head.getCurrentItem(); currentItem++;//赋给viewpagervp_head.setCurrentItem(currentItem); }};
//设置最大的长度vp_head.setCurrentItem(head.length * 5000); //小圆点跟随图片进行变化for (int i = 0; i < headlist.size(); i++) { if (i == position % 3) { headlist.get(i).setImageResource(R.drawable.dot_selected); } else { headlist.get(i).setImageResource(R.drawable.dot_notmal); } }/** * 自动轮播的方法 */ public void auto() { Timer timer = new Timer(); TimerTask task = new TimerTask() { @Override public void run() { handler.sendEmptyMessage(0); } }; timer.schedule(task, 0, 3000); }/** * 添加小圆点的方法 */ public void dotinit() { //viewpager图片的长度 for (int i = 0; i < head.length; i++) { //圆点的Imageview ImageView iv_dot = new ImageView(getContext()); //如果是选中页,变成红色 if (i == 0) { iv_dot.setImageResource(R.drawable.dot_selected); } else { iv_dot.setImageResource(R.drawable.dot_notmal); } LinearLayout.LayoutParams params = new LinearLayout.LayoutParams(25, 25); params.setMargins(10, 0, 10, 0); //给LinearLayout添加布局 layout_head.addView(iv_dot, params); //图片的集合 headlist.add(iv_dot); } }
自动轮播+无限轮播
最新推荐文章于 2024-04-15 10:28:24 发布