无限轮播
Posted glj521
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了无限轮播相关的知识,希望对你有一定的参考价值。
动态生产小圆点
public void setvpdata() { if(ivlist!=null){ ivlist.clear(); } if(ll.getChildCount()>0){ ll.removeAllViews(); } for (int i = 0; i < vplist.size(); i++) { ImageView iv = new ImageView(getActivity()); if(i==0){ iv.setImageResource(R.drawable.vp_shap); }else{ iv.setImageResource(R.drawable.vp_shap_normal); } LayoutParams params = new LayoutParams(10, 10); params.setMargins(10, 0, 10, 0); ll.addView(iv,params); ivlist.add(iv); }
public void setData() { vp.setAdapter(new ViewPagerAdapter(getActivity(),vplist)); vp.setCurrentItem(100000); vp.setOnPageChangeListener(new OnPageChangeListener() { @Override public void onPageSelected(int arg0) { for (int i = 0; i < ivlist.size(); i++) { if(i==arg0%ivlist.size()){ ivlist.get(arg0%ivlist.size()).setImageResource(R.drawable.vp_shap); }else{ ivlist.get(i).setImageResource(R.drawable.vp_shap_normal); } } } @Override public void onPageScrolled(int arg0, float arg1, int arg2) { // TODO Auto-generated method stub } @Override public void onPageScrollStateChanged(int arg0) { // TODO Auto-generated method stub } }); myhandler.sendEmptyMessageDelayed(1, 2000); }
private Handler myhandler = new Handler(){ public void handleMessage(android.os.Message msg) { switch (msg.what) { case 1: int len = vp.getCurrentItem(); len++; vp.setCurrentItem(len); myhandler.sendEmptyMessageDelayed(1, 2000); break; } }; };
以上是关于无限轮播的主要内容,如果未能解决你的问题,请参考以下文章