Android實(shí)現(xiàn)水平帶刻度的進(jìn)度條
本文實(shí)例為大家分享了Android實(shí)現(xiàn)水平帶刻度進(jìn)度條的具體代碼,供大家參考,具體內(nèi)容如下
效果
1、attrsl.xml
<!-- 帶刻度的 進(jìn)度條 --> ? ? <declare-styleable name="HorizontalProgressSeekBar"> ? ? ? ? <attr name="progressColor" /> ? ? ? ? <attr name="max" /> ? ? ? ? <attr name="progressContentIcon" format="reference" /> ? ? ? ? <attr name="progressGoalIcon" format="reference" /> ? ? ? ? <attr name="progressGoalIconWidthHeight" format="dimension" /> ? ? ? ? <attr name="progressContentIconHeight" format="dimension" /> ? ? ? ? <attr name="progressContentIconWidth" format="dimension" /> ? ? ? ? <attr name="progressDistance" format="dimension" /> </declare-styleable>
2、HorizontalProgressSeekBar.class
public class HorizontalProgressSeekBar extends View { ? ? private int viewWidth; ? ? private int viewHeight; ? ? private Paint strokePain; ? ? private List<Integer> goalTimes; ? ? private int maxData = 80; ? ? private Bitmap progressGoalBitmap; ? ? private Bitmap progressContentBitmap; ? ? private float proceedTime; ? ? private int PROGRESS_COLOR = Color.parseColor("#FE78A6"); ? ? private float goalProportion; ? ? private Paint backgroundPaint; ? ? private int distance = 10; ? ? private int distancePxMax; ? ? private int distancePxMin; ? ? private int distancePx; ? ? private RectF rectF; ? ? private List<Integer> bitmapType; ? ? private Bitmap bitmapHomeCornerKick; ? ? private Bitmap bitmapHomeTeamRedCard; ? ? private Bitmap bitmapHomeTeamScored; ? ? private Bitmap bitmapVisitingCornerKick; ? ? private Bitmap bitmapVisitingTeamScored; ? ? private List<BollProgressDataBean> homeTeamIncidentList; ? ? private List<BollProgressDataBean> visitingTeamIncidentList; ? ? private BollProgressDataBean homeTeamIncidentListBean; ? ? private BollProgressDataBean visitingTeamIncidentListBean; ? ? private RectF rectFStrokePain; ? ? private int bitmapHomeCornerKickWidth; ? ? private int bitmapHomeTeamScoredWidth; ? ? ? /** ? ? ?* 繪制進(jìn)球 時(shí)刻上主隊(duì) ? ? ?* ? ? ?* @param canvas ? ? ?*/ ? ? private float incidentTimeNumber; ? ? ? public HorizontalProgressSeekBar(Context context) { ? ? ? ? this(context, null); ? ? } ? ? ? public HorizontalProgressSeekBar(Context context, AttributeSet attrs) { ? ? ? ? this(context, attrs, 0); ? ? } ? ? ? public HorizontalProgressSeekBar(Context context, AttributeSet attrs, int defStyleAttr) { ? ? ? ? super(context, attrs, defStyleAttr); ? ? ? ? TypedArray a = context.obtainStyledAttributes(attrs, R.styleable.HorizontalProgressSeekBar); ? ? ? ? try { ? ? ? ? ? ? PROGRESS_COLOR = a.getColor(R.styleable.HorizontalProgressSeekBar_progressColor, PROGRESS_COLOR); ? ? ? ? ? ? maxData = a.getInt(R.styleable.HorizontalProgressSeekBar_max, maxData); ? ? ? ? ? ? int progressContentIconWidth = (int) a.getDimension(R.styleable.HorizontalProgressSeekBar_progressContentIconWidth, dipToPx(22)); ? ? ? ? ? ? int progressContentIconHeight = (int) a.getDimension(R.styleable.HorizontalProgressSeekBar_progressContentIconHeight, dipToPx(25)); ? ? ? ? ? ? progressContentBitmap = Bitmap.createScaledBitmap(BitmapFactory.decodeResource(getContext().getResources(), ? ? ? ? ? ? ? ? ? ? a.getResourceId(R.styleable.HorizontalProgressSeekBar_progressContentIcon, R.mipmap.rest)), progressContentIconWidth, progressContentIconHeight, true); ? ? ? ? ? ? int progressGoalIconWidthHeight = (int) a.getDimension(R.styleable.HorizontalProgressSeekBar_progressGoalIconWidthHeight, dipToPx(22)); ? ? ? ? ? ? progressGoalBitmap = Bitmap.createScaledBitmap(BitmapFactory.decodeResource(getContext().getResources(), ? ? ? ? ? ? ? ? ? ? a.getResourceId(R.styleable.HorizontalProgressSeekBar_progressGoalIcon, R.drawable.share)), progressGoalIconWidthHeight, progressGoalIconWidthHeight, true); ? ? ? ? ? ? ? bitmapHomeCornerKick = Bitmap.createScaledBitmap(BitmapFactory.decodeResource(getContext().getResources(), ? ? ? ? ? ? ? ? ? ? R.mipmap.home_corner_kick_xiao), progressGoalIconWidthHeight, progressGoalIconWidthHeight, true); ? ? ? ? ? ? bitmapHomeTeamRedCard = Bitmap.createScaledBitmap(BitmapFactory.decodeResource(getContext().getResources(), ? ? ? ? ? ? ? ? ? ? R.mipmap.home_team_red_card_xiao), progressGoalIconWidthHeight, progressGoalIconWidthHeight, true); ? ? ? ? ? ? bitmapHomeTeamScored = Bitmap.createScaledBitmap(BitmapFactory.decodeResource(getContext().getResources(), ? ? ? ? ? ? ? ? ? ? R.mipmap.home_team_scored_xiao), progressGoalIconWidthHeight, progressGoalIconWidthHeight, true); ? ? ? ? ? ? bitmapVisitingCornerKick = Bitmap.createScaledBitmap(BitmapFactory.decodeResource(getContext().getResources(), ? ? ? ? ? ? ? ? ? ? R.mipmap.visiting_corner_kick_xiao), progressGoalIconWidthHeight, progressGoalIconWidthHeight, true); ? ? ? ? ? ? bitmapVisitingTeamScored = Bitmap.createScaledBitmap(BitmapFactory.decodeResource(getContext().getResources(), ? ? ? ? ? ? ? ? ? ? R.mipmap.visiting_team_scored_xiao), progressGoalIconWidthHeight, progressGoalIconWidthHeight, true); ? ? ? ? ? ? ? ? distancePx = ?a.getDimensionPixelOffset(R.styleable.HorizontalProgressSeekBar_progressDistance,dipToPx(distance)); ? ? ? ? ? ? ? ? if (bitmapHomeCornerKick != null){ ? ? ? ? ? ? ? ? bitmapHomeCornerKickWidth = bitmapHomeCornerKick.getWidth(); ? ? ? ? ? ? } ? ? ? ? ? ? ? if (bitmapHomeTeamScored != null){ ? ? ? ? ? ? ? ? bitmapHomeTeamScoredWidth = bitmapHomeTeamScored.getWidth(); ? ? ? ? ? ? } ? ? ? ? ? } finally { ? ? ? ? ? ? a.recycle(); ? ? ? ? } ? ? ? ? ? distancePxMax = dipToPx(distance + 2); ? ? ? ? distancePxMin = dipToPx(distance - 2); ? ? ? ? strokePain = new Paint(); ? ? ? ? backgroundPaint = new Paint(); ? ? } ? ? ? /** ? ? ?* 設(shè)置進(jìn)球時(shí)間狀態(tài) ? ? ?* ? ? ?* @param goalTimes ? ? ?*/ ? ? public void setGoalTime(int max, float proceedTime, List<Integer> goalTimes) { ? ? ? ? this.maxData = max; ? ? ? ? this.proceedTime = proceedTime; ? ? ? ? this.goalTimes = goalTimes; ? ? ? ? invalidateView(); ? ? } ? ? ? /** ? ? ?* 設(shè)置進(jìn)球時(shí)間狀態(tài) ? ? ?* max 計(jì)算90由于中間遮擋效果,所以傳遞按照100? ? ? ?* homeTeamIncidentList 主隊(duì)時(shí)間和事件 ? ? ?* visitingTeamIncidentList ?客隊(duì)時(shí)間和事件 ? ? ?*/ ? ? public void setGoalTimeBitmap(int max, float proceedTime, List<BollProgressDataBean> homeTeamIncidentList, List<BollProgressDataBean> visitingTeamIncidentList) { ? ? ? ? this.maxData = max; ? ? ? ? this.proceedTime = proceedTime; ? ? ? ? this.homeTeamIncidentList = homeTeamIncidentList; ? ? ? ? this.visitingTeamIncidentList = visitingTeamIncidentList; ? ? ? ? invalidateView(); ? ? } ? ? ? public void setBitmapType(List<Integer> bitmapType) { ? ? ? ? this.bitmapType = bitmapType; ? ? ? ? invalidateView(); ? ? } ? ? ? @Override ? ? protected void onSizeChanged(int w, int h, int oldw, int oldh) { ? ? ? ? super.onSizeChanged(w, h, oldw, oldh); ? ? ? ? viewWidth = w; ? ? ? ? viewHeight = h; ? ? } ? ? ? @Override ? ? protected void onDraw(Canvas canvas) { ? ? ? ? super.onDraw(canvas); ? ? ? ? drawProgress(canvas); ? ? ? ? drawBorder(canvas); ? ? ? ? drawMeasureBorder(canvas); ? ? ? ? drawImage(canvas); ? ? ? ? drawGoalTime(canvas); ? ? ? ? drawGoalTimeButton(canvas); ? ? } ? ? ? /** ? ? ?* 繪制空心 長方形 ? ? ?* ? ? ?* @param canvas ? ? ?*/ ? ? private void drawBorder(Canvas canvas) { ? ? ? ? strokePain.reset(); ? ? ? ? strokePain.setStyle(Paint.Style.STROKE); ? ? ? ? strokePain.setAntiAlias(true); ? ? ? ? strokePain.setStrokeWidth(2); ? ? ? ? strokePain.setColor(Color.parseColor("#151515")); ? ? ? ? rectFStrokePain = new RectF(distancePx, viewHeight * 0.35f, viewWidth - distancePx, viewHeight * 0.65f); ? ? ? ? canvas.drawRect(rectFStrokePain, strokePain); ? ? } ? ? ? private void drawProgress(Canvas canvas) { ? ? ? ? strokePain.reset(); ? ? ? ? strokePain.setStyle(Paint.Style.FILL); ? ? ? ? strokePain.setAntiAlias(true); ? ? ? ? strokePain.setStrokeWidth(2); ? ? ? ? strokePain.setColor(Color.parseColor("#258940")); ? ? ? ? if (proceedTime <= 45) { ? ? ? ? ? ? rectF = new RectF(distancePx, viewHeight * 0.35f, ((float) viewWidth - 2 * distancePx) * (proceedTime / maxData) + distancePx, viewHeight * 0.65f); ? ? ? ? } else { ? ? ? ? ? ? if (proceedTime >= 90) { ? ? ? ? ? ? ? ? rectF = new RectF(distancePx, viewHeight * 0.35f, ((float) viewWidth - 2 * distancePx) * ((proceedTime + distance) / maxData) + distancePx, viewHeight * 0.65f); ? ? ? ? ? ? } else { ? ? ? ? ? ? ? ? rectF = new RectF(distancePx, viewHeight * 0.35f, ((float) viewWidth - 2 * distancePx) * ((proceedTime + distance) / maxData) + distancePx, viewHeight * 0.65f); ? ? ? ? ? ? } ? ? ? ? } ? ? ? ? ? canvas.drawRect(rectF, strokePain); ? ? } ? ? ? /** ? ? ?* 繪制刻度 ? ? ?* ? ? ?* @param canvas ? ? ?*/ ? ? private void drawMeasureBorder(Canvas canvas) { ? ? ? ? strokePain.setStyle(Paint.Style.STROKE); ? ? ? ? float eachWidth = (viewWidth - 2 * distancePx) / 20; ? ? ? ? strokePain.setStrokeWidth(2); ? ? ? ? int drawNoNumber = 20 / 2; ? ? ? ? strokePain.setColor(Color.parseColor("#FF424242")); ? ? ? ? for (int i = 1; i <= 19; i++) { ? ? ? ? ? ? //長短線條 ? ? ? ? ? ? if (drawNoNumber != i && i != 9 && i != 11) { ? ? ? ? ? ? ? ? if (i % 2 == 0) { ? ? ? ? ? ? ? ? ? ? canvas.drawLine(eachWidth * i + distancePx, viewHeight * 0.66f, eachWidth * i + distancePx, viewHeight * 0.45f, strokePain); ? ? ? ? ? ? ? ? } else { ? ? ? ? ? ? ? ? ? ? canvas.drawLine(eachWidth * i + distancePx, viewHeight * 0.66f, eachWidth * i + distancePx, viewHeight * 0.55f, strokePain); ? ? ? ? ? ? ? ? } ? ? ? ? ? ? } ? ? ? ? } ? ? } ? ? ? /** ? ? ?* 繪制H 圖片 ? ? ?* ? ? ?* @param canvas ? ? ?*/ ? ? private void drawImage(Canvas canvas) { ? ? ? ? if (progressContentBitmap != null) { ? ? ? ? ? ? canvas.drawBitmap(progressContentBitmap, ?(int) (viewWidth / 2.0 - progressContentBitmap.getWidth() / 2.0 ), (int) (viewHeight / 2.0 - (progressContentBitmap.getHeight()) / 2.0f), strokePain); ? ? ? ? } ? ? ? } ? ? ? ? private void drawGoalTime(Canvas canvas) { ? ? ? ? //主隊(duì)比賽中的事件 ?14角球 2紅牌 1進(jìn)球 ? ? ? ? ? if (homeTeamIncidentList != null && homeTeamIncidentList.size() > 0) { ? ? ? ? ? ? for (int i = 0; i < homeTeamIncidentList.size(); i++) { ? ? ? ? ? ? ? ? homeTeamIncidentListBean = homeTeamIncidentList.get(i); ? ? ? ? ? ? ? ? String incidentTime = homeTeamIncidentListBean.getIncidentTime(); ? ? ? ? ? ? ? ? String incidentType = homeTeamIncidentListBean.getIncidentType(); ? ? ? ? ? ? ? ? if (incidentTime != null) { ? ? ? ? ? ? ? ? ? ? try { ? ? ? ? ? ? ? ? ? ? ? ? incidentTimeNumber = Float.parseFloat(incidentTime); ? ? ? ? ? ? ? ? ? ? } catch (Exception e) { ? ? ? ? ? ? ? ? ? ? ? } ? ? ? ? ? ? ? ? ? } ? ? ? ? ? ? ? ? if (incidentTimeNumber == 0) { ? ? ? ? ? ? ? ? ? ? if (incidentType != null) { ? ? ? ? ? ? ? ? ? ? ? ? if ("14".equals(incidentType)) { ? ? ? ? ? ? ? ? ? ? ? ? ? ? homeIncidentZero(canvas, bitmapHomeCornerKick, incidentTimeNumber, 0.15f, incidentType); ? ? ? ? ? ? ? ? ? ? ? ? } else if ("2".equals(incidentType)) { ? ? ? ? ? ? ? ? ? ? ? ? ? ? homeIncidentZero(canvas, bitmapHomeTeamRedCard, incidentTimeNumber, 0.25f, incidentType); ? ? ? ? ? ? ? ? ? ? ? ? } else if ("1".equals(incidentType)) { ? ? ? ? ? ? ? ? ? ? ? ? ? ? homeIncidentZero(canvas, bitmapHomeTeamScored, incidentTimeNumber, 0.25f, incidentType); ? ? ? ? ? ? ? ? ? ? ? ? } ? ? ? ? ? ? ? ? ? ? } ? ? ? ? ? ? ? ? } else if (incidentTimeNumber <= 45 && incidentTimeNumber > 0) { ? ? ? ? ? ? ? ? ? ? if (incidentType != null) { ? ? ? ? ? ? ? ? ? ? ? ? if ("14".equals(incidentType)) { ? ? ? ? ? ? ? ? ? ? ? ? ? ? homeTeamIncident(canvas, bitmapHomeCornerKick, incidentTimeNumber, 0.15f, incidentType); ? ? ? ? ? ? ? ? ? ? ? ? } else if ("2".equals(incidentType)) { ? ? ? ? ? ? ? ? ? ? ? ? ? ? homeTeamIncident(canvas, bitmapHomeTeamRedCard, incidentTimeNumber, 0.25f, incidentType); ? ? ? ? ? ? ? ? ? ? ? ? } else if ("1".equals(incidentType)) { ? ? ? ? ? ? ? ? ? ? ? ? ? ? homeTeamIncident(canvas, bitmapHomeTeamScored, incidentTimeNumber, 0.25f, incidentType); ? ? ? ? ? ? ? ? ? ? ? ? } ? ? ? ? ? ? ? ? ? ? } ? ? ? ? ? ? ? ? ? } else if (incidentTimeNumber > 45 && incidentTimeNumber < 90) { ? ? ? ? ? ? ? ? ? ? if (incidentType != null) { ? ? ? ? ? ? ? ? ? ? ? ? if ("14".equals(incidentType)) { ? ? ? ? ? ? ? ? ? ? ? ? ? ? homeIncident(canvas, bitmapHomeCornerKick, incidentTimeNumber, 0.15f, incidentType); ? ? ? ? ? ? ? ? ? ? ? ? } else if ("2".equals(incidentType)) { ? ? ? ? ? ? ? ? ? ? ? ? ? ? homeIncident(canvas, bitmapHomeTeamRedCard, incidentTimeNumber, 0.25f, incidentType); ? ? ? ? ? ? ? ? ? ? ? ? } else if ("1".equals(incidentType)) { ? ? ? ? ? ? ? ? ? ? ? ? ? ? homeIncident(canvas, bitmapHomeTeamScored, incidentTimeNumber, 0.25f, incidentType); ? ? ? ? ? ? ? ? ? ? ? ? } ? ? ? ? ? ? ? ? ? ? } ? ? ? ? ? ? ? ? } else if (incidentTimeNumber >= 90) { ? ? ? ? ? ? ? ? ? ? if (incidentType != null) { ? ? ? ? ? ? ? ? ? ? ? ? incidentTimeNumber=90; ? ? ? ? ? ? ? ? ? ? ? ? if ("14".equals(incidentType)) { ? ? ? ? ? ? ? ? ? ? ? ? ? ? homeIncidentNinety(canvas, bitmapHomeCornerKick, incidentTimeNumber, 0.15f, incidentType); ? ? ? ? ? ? ? ? ? ? ? ? } else if ("2".equals(incidentType)) { ? ? ? ? ? ? ? ? ? ? ? ? ? ? homeIncidentNinety(canvas, bitmapHomeTeamRedCard, incidentTimeNumber, 0.25f, incidentType); ? ? ? ? ? ? ? ? ? ? ? ? } else if ("1".equals(incidentType)) { ? ? ? ? ? ? ? ? ? ? ? ? ? ? homeIncidentNinety(canvas, bitmapHomeTeamScored, incidentTimeNumber, 0.25f, incidentType); ? ? ? ? ? ? ? ? ? ? ? ? } ? ? ? ? ? ? ? ? ? ? } ? ? ? ? ? ? ? ? } ? ? ? ? ? ? } ? ? ? ? } ? ? ? } ? ? ? /** ? ? ?* 繪制進(jìn)球 時(shí)刻下客隊(duì) ? ? ?* ? ? ?* @param canvas ? ? ?*/ ? ? private void drawGoalTimeButton(Canvas canvas) { ? ? ? ? ? if (visitingTeamIncidentList != null && visitingTeamIncidentList.size() > 0) { ? ? ? ? ? ? for (int i = 0; i < visitingTeamIncidentList.size(); i++) { ? ? ? ? ? ? ? ? visitingTeamIncidentListBean = visitingTeamIncidentList.get(i); ? ? ? ? ? ? ? ? String incidentTime = visitingTeamIncidentListBean.getIncidentTime(); ? ? ? ? ? ? ? ? String incidentType = visitingTeamIncidentListBean.getIncidentType(); ? ? ? ? ? ? ? ? if (incidentTime != null) { ? ? ? ? ? ? ? ? ? ? try { ? ? ? ? ? ? ? ? ? ? ? ? incidentTimeNumber = Float.parseFloat(incidentTime); ? ? ? ? ? ? ? ? ? ? } catch (Exception e) { ? ? ? ? ? ? ? ? ? ? ? } ? ? ? ? ? ? ? ? ? } ? ? ? ? ? ? ? ? if (incidentTimeNumber == 0) { ? ? ? ? ? ? ? ? ? ? if (incidentType != null) { ? ? ? ? ? ? ? ? ? ? ? ? if ("14".equals(incidentType)) { ? ? ? ? ? ? ? ? ? ? ? ? ? ? homeIncidentZero(canvas, bitmapVisitingCornerKick, incidentTimeNumber, 0.56f, incidentType); ? ? ? ? ? ? ? ? ? ? ? ? } else if ("2".equals(incidentType)) { ? ? ? ? ? ? ? ? ? ? ? ? ? ? homeIncidentZero(canvas, bitmapHomeTeamRedCard, incidentTimeNumber, 0.45f, incidentType); ? ? ? ? ? ? ? ? ? ? ? ? } else if ("1".equals(incidentType)) { ? ? ? ? ? ? ? ? ? ? ? ? ? ? homeIncidentZero(canvas, bitmapVisitingTeamScored, incidentTimeNumber, 0.45f, incidentType); ? ? ? ? ? ? ? ? ? ? ? ? } ? ? ? ? ? ? ? ? ? ? } ? ? ? ? ? ? ? ? } else if (incidentTimeNumber <= 45 && incidentTimeNumber > 0) { ? ? ? ? ? ? ? ? ? ? if (incidentType != null) { ? ? ? ? ? ? ? ? ? ? ? ? if ("14".equals(incidentType)) { ? ? ? ? ? ? ? ? ? ? ? ? ? ? homeTeamIncident(canvas, bitmapVisitingCornerKick, incidentTimeNumber, 0.56f, incidentType); ? ? ? ? ? ? ? ? ? ? ? ? } else if ("2".equals(incidentType)) { ? ? ? ? ? ? ? ? ? ? ? ? ? ? homeTeamIncident(canvas, bitmapHomeTeamRedCard, incidentTimeNumber, 0.45f, incidentType); ? ? ? ? ? ? ? ? ? ? ? ? } else if ("1".equals(incidentType)) { ? ? ? ? ? ? ? ? ? ? ? ? ? ? homeTeamIncident(canvas, bitmapVisitingTeamScored, incidentTimeNumber, 0.45f, incidentType); ? ? ? ? ? ? ? ? ? ? ? ? } ? ? ? ? ? ? ? ? ? ? } ? ? ? ? ? ? ? ? ? } else if (incidentTimeNumber > 45 && incidentTimeNumber < 90) { ? ? ? ? ? ? ? ? ? ? if (incidentType != null) { ? ? ? ? ? ? ? ? ? ? ? ? if ("14".equals(incidentType)) { ? ? ? ? ? ? ? ? ? ? ? ? ? ? homeIncident(canvas, bitmapVisitingCornerKick, incidentTimeNumber, 0.56f, incidentType); ? ? ? ? ? ? ? ? ? ? ? ? } else if ("2".equals(incidentType)) { ? ? ? ? ? ? ? ? ? ? ? ? ? ? homeIncident(canvas, bitmapHomeTeamRedCard, incidentTimeNumber, 0.45f, incidentType); ? ? ? ? ? ? ? ? ? ? ? ? } else if ("1".equals(incidentType)) { ? ? ? ? ? ? ? ? ? ? ? ? ? ? homeIncident(canvas, bitmapVisitingTeamScored, incidentTimeNumber, 0.45f, incidentType); ? ? ? ? ? ? ? ? ? ? ? ? } ? ? ? ? ? ? ? ? ? ? } ? ? ? ? ? ? ? ? } else if (incidentTimeNumber >= 90) { ? ? ? ? ? ? ? ? ? ? if (incidentType != null) { ? ? ? ? ? ? ? ? ? ? ? ? incidentTimeNumber=90; ? ? ? ? ? ? ? ? ? ? ? ? if ("14".equals(incidentType)) { ? ? ? ? ? ? ? ? ? ? ? ? ? ? homeIncidentNinety(canvas, bitmapVisitingCornerKick, incidentTimeNumber, 0.56f, incidentType); ? ? ? ? ? ? ? ? ? ? ? ? } else if ("2".equals(incidentType)) { ? ? ? ? ? ? ? ? ? ? ? ? ? ? homeIncidentNinety(canvas, bitmapHomeTeamRedCard, incidentTimeNumber, 0.45f, incidentType); ? ? ? ? ? ? ? ? ? ? ? ? } else if ("1".equals(incidentType)) { ? ? ? ? ? ? ? ? ? ? ? ? ? ? homeIncidentNinety(canvas, bitmapVisitingTeamScored, incidentTimeNumber, 0.45f, incidentType); ? ? ? ? ? ? ? ? ? ? ? ? } ? ? ? ? ? ? ? ? ? ? } ? ? ? ? ? ? ? ? } ? ? ? ? ? ? } ? ? ? ? } ? ? } ? ? ? private void homeIncidentZero(Canvas canvas, Bitmap bitmapHomeCornerKick, float incidentTimeNumber, float v, String incidentType) { ? ? ? ? if ("14".equals(incidentType)) { ? ? ? ? ? ? canvas.drawBitmap(bitmapHomeCornerKick, (int) ((viewWidth - 2 * distancePx) * incidentTimeNumber / maxData - bitmapHomeCornerKickWidth / 2 + distancePxMax), viewHeight * v, strokePain); ? ? ? ? } else { ? ? ? ? ? ? canvas.drawBitmap(bitmapHomeCornerKick, (int) ((viewWidth - 2 * distancePx) * incidentTimeNumber / maxData - bitmapHomeCornerKickWidth / 2 + distancePx), viewHeight * v, strokePain); ? ? ? ? } ? ? ? } ? ? ? private void homeIncidentNinety(Canvas canvas, Bitmap bitmapHomeTeamScored, float incidentTimeNumber, float v, String incidentType) { ? ? ? ? if ("14".equals(incidentType)) { ? ? ? ? ? ? canvas.drawBitmap(bitmapHomeTeamScored, (int) ((viewWidth) * (incidentTimeNumber + 10) / maxData - bitmapHomeTeamScoredWidth / 2) - distancePxMin, viewHeight * v, strokePain); ? ? ? ? } else { ? ? ? ? ? ? canvas.drawBitmap(bitmapHomeTeamScored, (int) ((viewWidth) * (incidentTimeNumber + 10) / maxData - bitmapHomeTeamScoredWidth / 2) - distancePx, viewHeight * v, strokePain); ? ? ? ? } ? ? ? } ? ? ? private void homeIncident(Canvas canvas, Bitmap bitmapHomeTeamScored, float incidentTimeNumber, float v, String incidentType) { ? ? ? ? if ("14".equals(incidentType)) { ? ? ? ? ? ? canvas.drawBitmap(bitmapHomeTeamScored, (int) ((viewWidth - 2 * distancePx) * (incidentTimeNumber + 10) / maxData - bitmapHomeTeamScoredWidth / 2) + distancePxMax, viewHeight * v, strokePain); ? ? ? ? } else { ? ? ? ? ? ? canvas.drawBitmap(bitmapHomeTeamScored, (int) ((viewWidth - 2 * distancePx) * (incidentTimeNumber + 10) / maxData - bitmapHomeTeamScoredWidth / 2) + distancePx, viewHeight * v, strokePain); ? ? ? ? } ? ? } ? ? ? private void homeTeamIncident(Canvas canvas, Bitmap bitmapHomeCornerKick, float incidentTimeNumber, float v, String incidentType) { ? ? ? ? if ("14".equals(incidentType)) { ? ? ? ? ? ? canvas.drawBitmap(bitmapHomeCornerKick, (int) ((viewWidth - 2 * distancePx) * (incidentTimeNumber) / maxData - bitmapHomeCornerKickWidth / 2) + distancePxMax, viewHeight * v, strokePain); ? ? ? ? } else { ? ? ? ? ? ? canvas.drawBitmap(bitmapHomeCornerKick, (int) ((viewWidth - 2 * distancePx) * (incidentTimeNumber) / maxData - bitmapHomeCornerKickWidth / 2) + distancePx, viewHeight * v, strokePain); ? ? ? ? } ? ? ? } ? ? ? ? private void invalidateView() { ? ? ? ? if (Looper.getMainLooper() == Looper.myLooper()) { ? ? ? ? ? ? invalidate(); ? ? ? ? } else { ? ? ? ? ? ? postInvalidate(); ? ? ? ? } ? ? } ? ? ? private int dipToPx(float dip) { ? ? ? ? float density = getResources().getDisplayMetrics().density; ? ? ? ? return (int) (dip * density + 0.5f * (dip >= 0 ? 1 : -1)); ? ? } }
BollProgressDataBean.class
public class BollProgressDataBean { ? ? private String incidentType; ?//主隊(duì)比賽中的事件 ?0 角球 1紅牌 2進(jìn)球 ? ? private String incidentTime; ?//主隊(duì)比賽中發(fā)生事件的時(shí)間 ? ? ? public String getIncidentType() { ? ? ? ? return incidentType; ? ? } ? ? ? public void setIncidentType(String incidentType) { ? ? ? ? this.incidentType = incidentType; ? ? } ? ? ? public String getIncidentTime() { ? ? ? ? return incidentTime; ? ? } ? ? ? public void setIncidentTime(String incidentTime) { ? ? ? ? this.incidentTime = incidentTime; ? ? } }
以上就是本文的全部內(nèi)容,希望對(duì)大家的學(xué)習(xí)有所幫助,也希望大家多多支持腳本之家。
- Android 七種進(jìn)度條的樣式
- android自定義進(jìn)度條漸變色View的實(shí)例代碼
- Android中實(shí)現(xiàn)Webview頂部帶進(jìn)度條的方法
- Android文件下載進(jìn)度條的實(shí)現(xiàn)代碼
- Android編程之ProgressBar圓形進(jìn)度條顏色設(shè)置方法
- android ListView和ProgressBar(進(jìn)度條控件)的使用方法
- Android中自定義進(jìn)度條詳解
- 實(shí)例詳解Android自定義ProgressDialog進(jìn)度條對(duì)話框的實(shí)現(xiàn)
- android中實(shí)現(xiàn)OkHttp下載文件并帶進(jìn)度條
- Android 動(dòng)態(tài)改變SeekBar進(jìn)度條顏色與滑塊顏色的實(shí)例代碼
相關(guān)文章
Android利用CountDownTimer實(shí)現(xiàn)驗(yàn)證碼倒計(jì)時(shí)效果實(shí)例
這篇文章主要給大家介紹了關(guān)于Android如何利用CountDownTimer實(shí)現(xiàn)驗(yàn)證碼倒計(jì)時(shí)效果的相關(guān)資料,文中通過示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來一起學(xué)習(xí)學(xué)習(xí)吧。2017-10-10Android 使用Vitamio打造自己的萬能播放器(10)—— 本地播放 (縮略圖、視頻信息、視頻掃描服務(wù))
本文主要介紹Android 使用Vitamio開發(fā)播放器,這里主要講解本地播放 (縮略圖、視頻信息、視頻掃描服務(wù))等功能,有需要的小伙伴可以參考下2016-07-07flutter封裝點(diǎn)擊菜單工具欄組件checkBox多選版
這篇文章主要為大家介紹了flutter封裝一個(gè)點(diǎn)擊菜單工具欄組件,checkBox多選版的示例示例詳解,有需要的朋友可以借鑒參考下,希望能夠有所幫助,祝大家多多進(jìn)步,早日升職加薪2022-05-05實(shí)現(xiàn)一個(gè)Android鎖屏App功能的難點(diǎn)總結(jié)
這篇文章主要介紹了實(shí)現(xiàn)一個(gè)Android鎖屏App功能的難點(diǎn)總結(jié),可以有效的解決鎖屏開發(fā)的問題,有需要的可以參考一下。2016-11-11Android 網(wǎng)絡(luò)請(qǐng)求框架解析之okhttp與okio
HTTP是現(xiàn)代應(yīng)用常用的一種交換數(shù)據(jù)和媒體的網(wǎng)絡(luò)方式,高效地使用HTTP能讓資源加載更快,節(jié)省帶寬,OkHttp是一個(gè)高效的HTTP客戶端,下面這篇文章主要給大家介紹了關(guān)于OkHttp如何用于安卓網(wǎng)絡(luò)請(qǐng)求,需要的朋友可以參考下2021-10-10Android ScreenLockReceiver監(jiān)聽鎖屏功能示例
這篇文章主要介紹了Android ScreenLockReceiver監(jiān)聽鎖屏功能,結(jié)合實(shí)例形式分析了Android監(jiān)聽鎖屏及取消監(jiān)聽功能的具體實(shí)現(xiàn)技巧,需要的朋友可以參考下2017-07-07android實(shí)現(xiàn)可以滑動(dòng)的平滑曲線圖
這篇文章主要為大家詳細(xì)介紹了android實(shí)現(xiàn)可以滑動(dòng)的平滑曲線圖,文中示例代碼介紹的非常詳細(xì),具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下2022-06-06Android中將一個(gè)圖片切割成多個(gè)圖片的實(shí)現(xiàn)方法
有種場(chǎng)景,我們想將一個(gè)圖片切割成多個(gè)圖片。比如我們?cè)陂_發(fā)一個(gè)拼圖的游戲,就首先要對(duì)圖片進(jìn)行切割2013-05-05Android自定義View實(shí)現(xiàn)水波紋引導(dǎo)動(dòng)畫
這篇文章主要為大家詳細(xì)介紹了Android自定義View實(shí)現(xiàn)水波紋動(dòng)畫引導(dǎo),具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下2017-01-01