corners android:radius="10dp" solid android:color="@color/colorPrimary" 设置小圆点的java代码 private void initView() { vp = (ViewPager) findViewById(R.id.vp); vp.setAdapter(new MyPagerAdapt。无限轮播的小圆点设置。" />

无限轮播的小圆点设置

在drawable下设置 android:shape="oval"> corners android:radius="10dp" solid android:color="@color/colorPrimary"
设置小圆点的java代码 private void initView() {
vp = (ViewPager) findViewById(R.id.vp); vp.setAdapter(new MyPagerAdapter());
//获得存放dotView容器 ll = (LinearLayout) findViewById(R.id.ll);
//根据图片的个数生成小圆点 for (int i = 0; i < imgeList.size(); ++i){
View dotView = new View(this);
LinearLayout.LayoutParams params = new LinearLayout.LayoutParams(30,30); //设置控件与控件的间距 params.leftMargin = 10; params.rightMargin = 10;
dotView.setLayoutParams(params);
if(i == 0) { dotView.setBackgroundResource(R.drawable.shape_select); }else{ dotView.setBackgroundResource(R.drawable.shape_normal); }
//将点往容器中添加LinearLayout ll.addView(dotView); }
//为viewpager添加一个页面改变的监听 vp.addOnPageChangeListener(new ViewPager.OnPageChangeListener() { @Override public void onPageScrolled(int position, float positionOffset, int positionOffsetPixels) {
}
@Override public void onPageSelected(int position) {
//0,1,2这个是切换当前那个页面的状态 ll.getChildAt(position % imgeList.size()).setBackgroundResource(R.drawable.shape_select); //这个是将前一个点状态变更为未选中状态 ll.getChildAt(oldPosition % imgeList.size()).setBackgroundResource(R.drawable.shape_normal);
//更新圆点信息 oldPosition = position; }
@Override public void onPageScrollStateChanged(int state) {
} }); }

    推荐阅读