日本不卡不码高清免费观看,久久国产精品久久w女人spa,黄色aa久久,三上悠亚国产精品一区二区三区

您的位置:首頁技術文章
文章詳情頁

android實現簡單儀表盤效果

瀏覽:42日期:2022-09-18 13:36:17

本文實例為大家分享了android實現簡單儀表盤效果的具體代碼,供大家參考,具體內容如下

實現這個效果:

android實現簡單儀表盤效果

中間的文字很好寫,外層的進度條就需要自定義控件了,代碼如下:

public class CirCleProgressBar extends View { private Paint circlePaint; private Paint textPaint; private int circleColor;//圓弧顏色 private int circleBgColor;//圓弧背景顏色 private float circleWidth;//圓弧寬度 private float circleBgWidth;//圓弧背景寬度 private int textColor;//字體顏色 private float textSize;//字體大小 private int totalAngle;//總角度 private int startAngle;//開始角度 private float currentProgress;//當前進度 private float maxProgress;//最大進度 private float section;//分段 private float currentAngle;//當前角度 private float lastAngle; private ValueAnimator progressAnimator;//圓弧動畫 private int duration = 1000;//動畫時長 private boolean isDefaultText;//是否設置文字顯示的值 private String mTextValue;//字體顯示的值 public CirCleProgressBar(Context context) {this(context, null); } public CirCleProgressBar(Context context, AttributeSet attrs) {this(context, attrs, 0); } public CirCleProgressBar(Context context, AttributeSet attrs, int defStyleAttr) {super(context, attrs, defStyleAttr);circlePaint = new Paint();textPaint = new Paint();TypedArray typedArray = context.obtainStyledAttributes(attrs, R.styleable.CirCleProgressBar);circleColor = typedArray.getColor(R.styleable.CirCleProgressBar_circle_color, Color.RED);circleBgColor = typedArray.getColor(R.styleable.CirCleProgressBar_circle_bg_color, Color.YELLOW);circleWidth = typedArray.getDimension(R.styleable.CirCleProgressBar_circle_width, 2);circleBgWidth = typedArray.getDimension(R.styleable.CirCleProgressBar_circle_bg_width, 2);textColor = typedArray.getColor(R.styleable.CirCleProgressBar_text_color, Color.BLUE);textSize = typedArray.getDimension(R.styleable.CirCleProgressBar_text_size, 10);totalAngle = typedArray.getInteger(R.styleable.CirCleProgressBar_total_angle, 360);startAngle = typedArray.getInteger(R.styleable.CirCleProgressBar_start_angle, 0);currentProgress = typedArray.getFloat(R.styleable.CirCleProgressBar_current_progress, 0);maxProgress = typedArray.getFloat(R.styleable.CirCleProgressBar_max_progress, 100);setCurrentProgress(currentProgress);setMaxProgress(maxProgress);//typedArray.recycle(); } @SuppressLint('DrawAllocation') @Override protected void onDraw(Canvas canvas) {super.onDraw(canvas);/** * 畫最外層的大圓環 */int centre = getWidth() / 2; // 獲取圓心的x坐標int radius = (int) (centre - circleWidth / 2) - 2; // 圓環的半徑circlePaint.setColor(circleBgColor);circlePaint.setStyle(Paint.Style.STROKE);circlePaint.setAntiAlias(true);circlePaint.setStrokeCap(Paint.Cap.ROUND);// 圓頭circlePaint.setStrokeWidth(circleBgWidth);RectF oval = new RectF(centre - radius - 1, centre - radius - 1, centre + radius + 1, centre + radius + 1); // 用于定義的圓弧的形狀和大小的界限//背景圓canvas.drawArc(oval, startAngle, totalAngle, false, circlePaint);//數據圓circlePaint.setStrokeWidth(circleWidth);circlePaint.setColor(circleColor);canvas.drawArc(oval, startAngle, currentAngle, false, circlePaint);//textPaint.setAntiAlias(true);textPaint.setColor(textColor);textPaint.setTextSize(textSize);float textWidth = textPaint.measureText((int) currentProgress + '');if(!isDefaultText) { canvas.drawText(String.valueOf((int)currentProgress), centre - textWidth / 2, centre + textSize / 2, textPaint);}else { canvas.drawText(mTextValue, centre - textWidth / 2, centre + textSize / 2, textPaint);}//invalidate(); } public float getMaxProgress(){return maxProgress; } public void setMaxProgress(float maxProgress){if(maxProgress < 0){ throw new IllegalArgumentException('max not less than 0');}this.maxProgress = maxProgress;section = totalAngle / maxProgress; } public void setAnimationDuration(int duration){this.duration = duration; } public void setCurrentProgress(float progress){if(progress >= 0){ this.currentProgress = progress; if(progress > maxProgress){progress = maxProgress; } lastAngle = currentAngle; setAnimation(lastAngle, progress * section, duration);} } private void setAnimation(float last, float current, int duration){progressAnimator = ValueAnimator.ofFloat(last, current);progressAnimator.setDuration(duration);progressAnimator.setTarget(currentAngle);progressAnimator.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() { @Override public void onAnimationUpdate(ValueAnimator valueAnimator) {currentAngle = (float) valueAnimator.getAnimatedValue();currentProgress = currentAngle / section; }});progressAnimator.start(); } public int getCircleColor() {return circleColor; } public void setCircleColor(int circleColor) {this.circleColor = circleColor; } public int getCircleBgColor() {return circleBgColor; } public void setCircleBgColor(int circleBgColor) {this.circleBgColor = circleBgColor; } public float getCircleWidth() {return circleWidth; } public void setCircleWidth(float circleWidth) {this.circleWidth = circleWidth; } public float getCircleBgWidth() {return circleBgWidth; } public void setCircleBgWidth(float circleBgWidth) {this.circleBgWidth = circleBgWidth; } public int getTextColor() {return textColor; } public void setTextColor(int textColor) {this.textColor = textColor; } public float getTextSize() {return textSize; } public void setTextSize(float textSize) {this.textSize = textSize; } /** * @param isText 為true,自定義設置字體顯示 * @param text */ public void setText(boolean isText,String text){isDefaultText = isText;mTextValue = text; }}

需要在attrs中添加:

<declare-styleable name='CirCleProgressBar'><attr name='circle_color' format='color'/><attr name='circle_bg_color' format='color'/><attr name='circle_width' format='dimension'/><attr name='circle_bg_width' format='dimension'/><attr name='text_color' format='color'/><attr name='text_size' format='dimension'/><attr name='total_angle' format='integer'/><attr name='start_angle' format='integer'/><attr name='current_progress' format='float'/><attr name='max_progress' format='float'/></declare-styleable>

使用方法:

在布局文件中直接引用

<com.fm.newcinema.view.CirCleProgressBarandroid: android:layout_width='139dp'android:layout_height='99dp'android:layout_gravity='center_horizontal'android:layout_marginTop='8dp'app:circle_bg_color='@color/gray_line_ff'app:circle_bg_width='10dp'app:circle_color='@color/main_blue'app:circle_width='10dp'app:max_progress='100'app:start_angle='160'app:text_color='@color/white_ff'app:text_size='@dimen/size_30px'app:total_angle='221'/>

其中app:circle_bg_color表示進度條底層的顏色,app:circle_color表示進度條上層的顏色,app:circle_bg_width表示進度條底層的寬度,app:circle_width表示進度條上層的寬度,app:max_progress='100'表示進度條最大進度是100,app:start_angle表示開始的角度,就是進度條從哪個角度開始畫,如下圖所示

android實現簡單儀表盤效果

app:total_angle表示整個進度條所需的角度.在代碼中設置旋轉的角度,圖中進度為30%,由于在布局文件中設置的最大進度是100`app:max_progress='100',所以進行如下設置peocess.setCurrentProgress(30f)默認情況下,進度條中間顯示進度條的值,如果需要自己寫值的畫,調用這個方法:process.setText(true, '中間的字');

以上就是本文的全部內容,希望對大家的學習有所幫助,也希望大家多多支持好吧啦網。

標簽: Android
相關文章:
日本不卡不码高清免费观看,久久国产精品久久w女人spa,黄色aa久久,三上悠亚国产精品一区二区三区
欧美aa一级| 欧美日本不卡| 亚洲精品97| 蜜桃视频在线观看一区二区| 成人午夜精品| 老鸭窝亚洲一区二区三区| 91免费精品国偷自产在线在线| 久久国产精品美女| 久久一区二区三区喷水| 亚洲a成人v| 国产a亚洲精品| 99国产一区| 国产精品成人国产| 亚洲不卡av不卡一区二区| 在线综合亚洲| 欧美精品导航| 亚洲成人一区| 国产精一区二区| 韩国三级一区| 视频在线观看91| 精品一区二区男人吃奶| 欧美日韩国产在线观看网站| 欧美一区二区三区久久| 神马午夜久久| 香蕉久久一区| 日本不卡免费高清视频在线| 亚洲香蕉久久| 欧美日韩在线观看首页| 亚洲精品乱码日韩| 色偷偷色偷偷色偷偷在线视频| 丝袜美腿成人在线| 国产成人精品免费视| 亚洲精品国模| 四虎4545www国产精品 | 婷婷综合一区| 中文一区一区三区高中清不卡免费| 免费视频一区二区| 伊人久久视频| 国产精品综合| 视频一区二区中文字幕| 日韩av有码| 日韩av资源网| 欧美日韩视频一区二区三区| 精品一区二区三区的国产在线观看 | 99久久精品网| 国产日韩欧美在线播放不卡| 欧美特黄一级| 欧美国产小视频| 18国产精品| 国产精品美女| 日韩黄色大片| 国产精选一区| 亚洲人www| 国产精品7m凸凹视频分类| 卡一卡二国产精品| 亚洲精品三级| 欧美日韩视频| 久久久9色精品国产一区二区三区| 国产精品久久久一区二区| 蜜桃视频一区二区三区在线观看| 日韩精品一区二区三区免费观影 | 国产精品观看| 亚洲ab电影| 一级欧洲+日本+国产| 日韩欧美字幕| 国产另类在线| 日韩精品久久久久久久软件91| 视频一区中文| 成人日韩在线| 国内精品美女在线观看| 欧美影院精品| 午夜电影一区| 亚洲欧美日韩视频二区| 91精品啪在线观看国产18 | 国产精品1区| 日韩福利在线观看| 中文字幕日韩高清在线| 亚洲欧美伊人| 亚洲精品.com| 日韩欧美另类一区二区| 精品国产欧美| 精品国产中文字幕第一页| 国产精品亚洲综合色区韩国| 日韩成人av影视| 日韩毛片一区| 色综合视频一区二区三区日韩| 首页欧美精品中文字幕| 亚洲欧美日韩国产一区二区| 日韩一级精品| 另类国产ts人妖高潮视频| 免费日韩一区二区| 视频在线观看国产精品| 国产手机视频一区二区 | 久久不见久久见中文字幕免费 | 三上亚洲一区二区| 精品视频一二| 国产videos久久| 国产第一亚洲| 电影亚洲精品噜噜在线观看| 视频二区不卡| 亚洲高清影视| 免费在线观看不卡| 中文字幕一区二区av| 亚洲免费专区| 亚洲精品乱码久久久久久蜜桃麻豆| 午夜一级在线看亚洲| 亚洲一区二区三区无吗| 亚洲精选成人| 日韩激情网站| 国产精区一区二区| 电影91久久久| 日本高清不卡一区二区三区视频| 久久免费高清| 樱桃成人精品视频在线播放| 三级欧美韩日大片在线看| 亚洲精品免费观看| 911精品国产| 久久久久伊人| 播放一区二区| 午夜久久美女| 一区二区国产在线| 欧美日韩va| 岛国精品一区| 在线视频观看日韩| 一区二区亚洲视频| 日本欧美久久久久免费播放网| 国产精品theporn| 97精品视频在线看| 在线国产一区| 91精品尤物| 成人影视亚洲图片在线| 欧美日中文字幕| 最近国产精品视频| 卡一卡二国产精品| 亚洲四虎影院| 一级成人国产| 精品美女在线视频| re久久精品视频| 日本a级不卡| 成人亚洲欧美| 三级在线观看一区二区| 国产精东传媒成人av电影| 三级精品视频| 午夜精品影视国产一区在线麻豆| 精品视频一区二区三区在线观看 | 国产精品一国产精品k频道56| 国产精品久久久久久久免费观看 | 天堂精品久久久久| 国产在线一区不卡| 在线亚洲免费| 欧美精品91| 国产精品91一区二区三区| 欧美在线黄色| 激情综合自拍| 国产精品极品国产中出| 91精品91| 精品国产欧美日韩一区二区三区| 野花国产精品入口| 精品一区二区三区亚洲| 在线免费观看亚洲| 中文字幕成在线观看| 日本不卡一区二区三区| 成人福利av| 日本成人精品| 99精品小视频| 国产精品一区二区精品视频观看 | 日韩一区二区免费看| 免费在线亚洲| 美日韩精品视频| jizzjizz中国精品麻豆| 日韩一区二区三区免费视频 | 日韩美女一区二区三区在线观看| 亚洲无线观看| 福利片在线一区二区| 亚久久调教视频| 婷婷亚洲五月| 精品国产黄a∨片高清在线| 蜜乳av另类精品一区二区| 91日韩免费| 久久狠狠久久| 香蕉成人久久| 日韩欧美精品一区| 国产精品一区二区免费福利视频| 亚洲一区免费| 欧美日韩精品免费观看视欧美高清免费大片| 日本一不卡视频| 91成人精品| 欧美成人a交片免费看| 日韩精品a在线观看91| 好吊一区二区三区| 欧洲在线一区| 久久亚洲国产精品尤物| 亚洲精选91| 欧美日韩激情| 夜鲁夜鲁夜鲁视频在线播放| 国产情侣一区| 偷拍亚洲精品| 久色成人在线| 欧美日韩四区| 99久精品视频在线观看视频|