赞
踩
项目需求,需要做一个弧形的seekbar
先看下效果,可以点击滑动来确定级别的弧形seekbar。
直接上代码,代码有注释
package com.hughzhao.seekbardemo.ui; import android.content.Context; import android.graphics.Bitmap; import android.graphics.BitmapFactory; import android.graphics.Canvas; import android.graphics.Color; import android.graphics.Paint; import android.graphics.Path; import android.graphics.PixelFormat; import android.graphics.Point; import android.graphics.PointF; import android.graphics.drawable.Drawable; import android.util.AttributeSet; import android.util.Log; import android.view.MotionEvent; import android.view.View; import android.widget.Scroller; import java.math.BigDecimal; /** * 自定义弧形SeekBar * create by hugh zhao 2020/3/18 */ public class MySeekBar extends View { private Scroller scroller; //画笔 private Paint paint; private Path path; private PointF pointF1; // 起始点 private PointF pointF2; // 控制点 private PointF pointF3; // 终止点 Bitmap mThumbBitmap;//设置圆球的样式 private int mThumbWidth;//圆球的宽度 private int top;//当前view的参数 private int right; private int bottom; private int left; private float currentX; // 当前x坐标 private int currentLevel ; // 当前档次 private int defaultLevel = 1; private OnProgressChangedListener listener; private int mLevel ; // 设置档次 public MySeekBar(Context context) { super(context); init(context); } public MySeekBar(Context context, AttributeSet attrs) { super(context, attrs); init(context); } public MySeekBar(Context context, AttributeSet attrs, int defStyleAttr) { super(context, attrs, defStyleAttr); init(context); } private void init(Context context) { paint = new Paint(); path = new Path(); pointF1 = new Poi
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。