| 12
 3
 4
 5
 6
 7
 8
 9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 
 | public class Inject extends FrameLayout implements ViewPager.OnPageChangeListener {private ShapeDrawable selectShape;
 private MyVp mViewPager;
 private ShapeDrawable defaultShape;
 private View moveView;
 
 public Inject(Context context) {
 this(context, null);
 }
 
 public Inject(Context context, AttributeSet attrs) {
 this(context, attrs, 0);
 }
 
 public Inject(Context context, AttributeSet attrs, int defStyleAttr) {
 super(context, attrs, defStyleAttr);
 
 {
 
 OvalShape ovalShape = new OvalShape();
 defaultShape = new ShapeDrawable(ovalShape);
 defaultShape.getPaint().setColor(Color.BLACK);
 defaultShape.getPaint().setStyle(Paint.Style.FILL_AND_STROKE);
 }
 
 {
 
 OvalShape ovalShape = new OvalShape();
 selectShape = new ShapeDrawable(ovalShape);
 selectShape.getPaint().setColor(Color.rgb(0x75, 0xd1, 0xd9));
 selectShape.getPaint().setStyle(Paint.Style.FILL_AND_STROKE);
 }
 
 }
 
 
 public void setViewPager(MyVp vp, boolean isInfinite) {
 this.mViewPager = vp;
 mViewPager.addOnPageChangeListener(this);
 initView();
 }
 
 @Override
 protected void onDetachedFromWindow() {
 
 if (mViewPager != null)
 mViewPager.removeOnPageChangeListener(this);
 mViewPager = null;
 super.onDetachedFromWindow();
 }
 
 
 private void initView() {
 
 for (int i = 0; i < mViewPager.getAdapter().getCount(); i++) {
 View v = new View(getContext());
 v.setBackgroundDrawable(defaultShape);
 LayoutParams layoutParams = new LayoutParams(14, 14);
 layoutParams.leftMargin = i * 42;
 addView(v, layoutParams);
 }
 
 
 
 moveView = new View(getContext());
 moveView.setBackgroundDrawable(selectShape);
 LayoutParams layoutParams = new LayoutParams(14, 14);
 addView(moveView, layoutParams);
 }
 
 @Override
 public void onPageScrolled(int position, float positionOffset, int positionOffsetPixels) {
 
 LayoutParams layoutParams = (LayoutParams) moveView.getLayoutParams();
 layoutParams.leftMargin = (int) (position * 42 + (42 * positionOffset));
 moveView.setLayoutParams(layoutParams);
 }
 
 @Override
 public void onPageSelected(int position) {
 }
 
 @Override
 public void onPageScrollStateChanged(int state) {
 }
 }
 
 
 |