/***得到屏幕宽度**@return*/private intgetScreenWidth() {WindowManager windowManager = (WindowManager) getContext().getSystemService(Context.WINDOW_SERVICE);DisplayMetrics displayMetrics =newDisplayMetrics();windowManager.getDefaultDisplay().getMetrics(displayMetrics);returndisplayMetrics.widthPixels;
}
设置自定义控件的宽高,
@Overrideprotected voidonMeasure(intwidthMeasureSpec,intheightMeasureSpec) {intwidth = 4 * getScreenWidth() / 5;intheight = 4 * getScreenWidth() / 6 + getScreenWidth() / 10;setMeasuredDimension(width, height);}
设置自定义控件的位置:
private voidinitView() {diameter= 3 * getScreenWidth() / 5;//弧形的矩阵区域bgRect=newRectF();bgRect.top=longdegree+progressWidth/ 2 +DEGREE_PROGRESS_DISTANCE;bgRect.left=longdegree+progressWidth/ 2 +DEGREE_PROGRESS_DISTANCE;bgRect.right=diameter+ (longdegree+progressWidth/ 2 +DEGREE_PROGRESS_DISTANCE);bgRect.bottom=diameter+ (longdegree+progressWidth/ 2 +DEGREE_PROGRESS_DISTANCE);
}