设为首页 加入收藏

TOP

android-自定义控件之液位指示器(二)
2017-10-12 17:57:17 】 浏览:8755
Tags:android- 定义 控件 液位 指示器
P, dpVal, getResources().getDisplayMetrics()); } /** * sp 2 px * */ protected int sp2px(int spVal) { return (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_SP, spVal, getResources().getDisplayMetrics()); } private Paint paintCheek = new Paint(); private Paint paint = new Paint(); private float radio; private float progressNowHeight; public JianWWIndicateProgress(Context context) { this(context, null); } public JianWWIndicateProgress(Context context, AttributeSet asets) { this(context, asets, 0); } public JianWWIndicateProgress(Context context, AttributeSet asets, int defStyle) { super(context, asets, defStyle); obtainStyledAttributes(asets); // paint.setTextSize(reachedTextsize); // paint.setColor(reachedTextcolor); } /** * 定义属性 * * @param asets属性 */ private void obtainStyledAttributes(AttributeSet asets) { final TypedArray typeArray = getContext().obtainStyledAttributes(asets, R.styleable.JianWWIndicateProgress); unReachedColor = typeArray.getColor(R.styleable.JianWWIndicateProgress_progress_unreachedcolor, unreached_color); reachedColor = typeArray.getColor(R.styleable.JianWWIndicateProgress_progress_reached_color, reached_color);// 到达颜色 progressHeight = (int) typeArray.getDimension(R.styleable.JianWWIndicateProgress_progress_height, progress_height); progressWidth = dp2px( (int) typeArray.getDimension(R.styleable.JianWWIndicateProgress_progress_width, progress_width));// 容器的总宽度 reachedHeight = (int) typeArray.getDimension(R.styleable.JianWWIndicateProgress_progress_reached_height, reached_height);// 到达的高度 cheekWidth = (int) typeArray.getDimension(R.styleable.JianWWIndicateProgress_progress_cheek_width, progress_cheek_width);// 容器的边框宽度 cheekColor = typeArray.getColor(R.styleable.JianWWIndicateProgress_progress_cheek_color, progress_cheek_color); reachedTextsize = (int) typeArray.getDimension(R.styleable.JianWWIndicateProgress_progress_reached_textsize, progress_reached_textsize);// 指示字体尺寸 reachedTextcolor = typeArray.getColor(R.styleable.JianWWIndicateProgress_progress_reached_textcolor, progress_reached_textcolor);// 指示字体颜色 typeArray.recycle(); } /** * onMeasure是对绘出的控件将来占的空间进行的安排, */ @Override protected synchronized void onMeasure(int widthMeasureSpec, int heightMeasureSpec) { super.onMeasure(widthMeasureSpec, heightMeasureSpec); int totalWidth = measurdWidth(widthMeasureSpec); int totalHeight = measurdHeight(heightMeasureSpec); setMeasuredDimension(totalWidth, totalHeight); } /** * * @param widthMeasureSpec * @return 获取宽度尺寸 */ private int measurdWidth(int widthMeasureSpec) { int result = 0; int widthSpaceSize = MeasureSpec.getSize(widthMeasureSpec); int widthSpaceMode = MeasureSpec.getMode(widthMeasureSpec); if (widthSpaceMode == MeasureSpec.EXACTLY) { result = widthSpaceSize; widthZoom = widthSpaceSize/(progressWidth+2*cheekWidth); progressWidth = (int) (progressWidth * widthZoom); } else if (widthSpaceMode == MeasureSpec.UNSP
首页 上一页 1 2 3 4 下一页 尾页 2/4/4
】【打印繁体】【投稿】【收藏】 【推荐】【举报】【评论】 【关闭】 【返回顶部
上一篇Android Material Design 下一篇春秋旅行安卓客户端源码项目

最新文章

热门文章

Hot 文章

Python

C 语言

C++基础

大数据基础

linux编程基础

C/C++面试题目