当前位置: 代码迷 >> Android >> android下小圆点page控件
  详细解决方案

android下小圆点page控件

热度:96   发布时间:2016-05-01 19:21:03.0
android上小圆点page控件
public class PointPageView extends View {		private int mPageSize;	private int mPageIndex;	private int mPointSize;	private int mPointSpan;	private int mSelectPointSize;	private int mStep;	private int mDisplaySize;	private int mDisplayIndex;	private Paint paint;		private void init() {		mPointSize = 3;		mSelectPointSize = mPointSize;		mPointSpan = 3 * mPointSize;		mStep = 1;		paint = new Paint();		paint.setAntiAlias(true);		paint.setColor(Color.WHITE);	}		public PointPageView(Context context) {		super(context, null);		init();	}	/**	 * Used to inflate the Workspace from XML.	 */	public PointPageView(Context context, AttributeSet attrs) {		super(context, attrs);		init();	}		public void setPageSize(int pageSize) {		mPageSize = Math.max(pageSize, 0);		mDisplaySize = (int)Math.ceil((double)mPageSize / mStep);		invalidate();	}		public int getPageSize() {		return mPageSize;	}		public void setPageIndex(int pageIndex) {		mPageIndex = Math.min(Math.max(pageIndex, 0), mPageSize - 1);		mDisplayIndex = (int)Math.floor((double)mPageIndex / mStep);		invalidate();	}		public int getPageIndex() {		return mPageIndex;	}		public void setColor(int color) {		paint.setColor(color);	}		public void setPointSize(int size) {		mPointSize = size;	}		public void setSelectPointSize(int size) {		mSelectPointSize = size;	}		public void setPointSpan(int span) {		mPointSpan = span;	}		public void setStep(int step) {		mStep = step;	}		public int getStep() {		return mStep;	}		@Override	public void draw(Canvas canvas) {		super.draw(canvas);		drawAllPoint(canvas);	}		private void drawAllPoint(Canvas canvas) {		canvas.save();				final int paddingLeft = mPointSpan;		final int width = getMeasuredWidth();		final int height = getMeasuredHeight();				int radius = mPointSize;		int contentWidth = (radius + paddingLeft) * mPageSize;		int beginX = (width - contentWidth) / 2;		int beginY = height / 2;		for (int i = 0; i < mDisplaySize; i++) {			if (i == mDisplayIndex) {				paint.setAlpha(255);				radius = mSelectPointSize;			} else {				paint.setAlpha(128);				radius = mPointSize;			}			canvas.drawCircle(beginX, beginY, radius, paint);			beginX = beginX + radius + radius + paddingLeft;		}				canvas.restore();	}}
  相关解决方案