动态生产小圆点
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; } }; };
时间: 2024-10-19 04:44:04