//适配器监听小圆点
vp.addOnPageChangeListener(new ViewPager.OnPageChangeListener() {
@Override
public void onPageScrolled(int position, float positionOffset, int positionOffsetPixels) {
}
@Override
public void onPageSelected(int position) {
int index = position % list_doc.size();
for (int i = 0; i < list_doc.size(); i++) {
list_doc.get(i).setBackgroundResource(R.drawable.doc_uncheck);
}
list_doc.get(index).setBackgroundResource(R.drawable.doc_check);
}
@Override
public void onPageScrollStateChanged(int state) {
}
});
}
@Override
public void lunbo(int index) {
vp.setCurrentItem(index);
}
//动态添加小圆点
//初始化小圆点
public void initDoc() {
list_doc = new ArrayList<ImageView>();
if (shouye_vp != null && shouye_vp.getStories().size() > 0) {
for (int i = 0; i < shouye_vp.getStories().size(); i++) {
ImageView iv = new ImageView(context);
params = new LinearLayout.LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT);
params.rightMargin = 10;
iv.setLayoutParams(params);
if (i == 0) {
iv.setBackgroundResource(R.drawable.doc_check);
} else {
iv.setBackgroundResource(R.drawable.doc_uncheck);
}
view.showDoc(iv);
list_doc.add(iv);
}
handler.postDelayed(new Runnable() {
@Override
public void run() {
index++;
view.lunbo(index);
handler.postDelayed(this, 3000);
}
}, 3000);
view.listener(list_doc);
}
//添加选择器样式
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="oval"
>
<solid android:color="#0ff"/>
<size android:width="15dp" android:height="15dp"/>
<stroke android:color="#0ff" android:width="1dp"/>
</shape>
网友评论