直播商城系统源码,自定义View实现方向控制控件,可拖拽中间圆
直播商城系统源码,自定义View实现方向控制控件,可拖拽中间圆
1 | public class DirectionView extends View implements View.OnTouchListener {<br> private int width;<br> private int height;<br> private int halfWidth;<br> private int halfHeight;<br> private int smallCircleRadius;<br> <br> private int sideWidth = 4; //外层边框宽度<br> <br> private Paint paintCircleSide;<br> private Paint paintCircleBg;<br> private Paint paintCircleCenter;<br> private Paint paintDirection;<br> <br> private int pressDirectionH = 0;<br> private int pressDirectionV = 0;<br> <br> private int smallCircleCenterX = -1;<br> private int smallCircleCenterY = -1;<br> private int halfTouchWidth = 65;<br> <br> private BlurMaskFilter blurMaskFilter;<br> private Path path = new Path();<br> <br> public DirectionView(Context context) {<br> super(context);<br> init(context);<br> }<br> <br> public DirectionView(Context context, @Nullable AttributeSet attrs) {<br> super(context, attrs);<br> init(context);<br> }<br> <br> public DirectionView(Context context, @Nullable AttributeSet attrs, int defStyleAttr) {<br> super(context, attrs, defStyleAttr);<br> init(context);<br> }<br> <br> private void init(Context context)<br> {<br> paintCircleSide = createPaintWithCommon(sideWidth, "#66ffffff", Paint.Style.STROKE);<br> paintCircleBg = createPaintWithCommon(2, "#662a3845", Paint.Style.FILL);<br> paintCircleCenter = createPaintWithCommon(2, "#ffffff", Paint.Style.FILL);<br> paintDirection = createPaintWithCommon(6, "#ffffff", Paint.Style.STROKE);<br> <br> blurMaskFilter = new BlurMaskFilter(20, BlurMaskFilter.Blur.SOLID);<br> <br> this.setOnTouchListener(this);<br> }<br> <br> private Paint createPaintWithCommon(int strokeWidth, String color, Paint.Style style)<br> {<br> Paint paint = new Paint();<br> paint.setStrokeWidth(strokeWidth);<br> paint.setColor(Color.parseColor(color));<br> paint.setStyle(style);<br> paint.setAntiAlias(true);<br> paint.setStrokeJoin(Paint.Join.ROUND);<br> paint.setStrokeCap(Paint.Cap.ROUND);<br> return paint;<br> }<br> <br> @Override<br> protected void onDraw(Canvas canvas) {<br> super.onDraw(canvas);<br> <br> canvas.drawCircle(halfWidth, halfHeight, halfWidth - sideWidth / 2, paintCircleBg);<br> canvas.drawCircle(halfWidth, halfHeight, halfWidth - sideWidth, paintCircleSide);<br> <br> if(this.smallCircleCenterY != -1)<br> {<br>// paintCircleCenter.setMaskFilter(blurMaskFilter);<br> canvas.drawCircle(smallCircleCenterX, smallCircleCenterY, smallCircleRadius, paintCircleCenter);<br> }<br> else<br> {<br>// paintCircleCenter.setMaskFilter(null);<br> canvas.drawCircle(halfWidth, halfHeight, smallCircleRadius, paintCircleCenter);<br> }<br> <br> int offsetSize = 25;<br> int offsetPosition = 20;<br> <br> //上<br> if(pressDirectionV == PtzAction.Direction.Up)<br> paintDirection.setColor(Color.parseColor("#0000ff"));<br> else<br> paintDirection.setColor(Color.parseColor("#ffffff"));<br> <br> path.reset();<br> path.moveTo(halfWidth - offsetSize, halfHeight / 2 - offsetPosition);<br> path.lineTo(halfWidth, halfHeight / 2 - offsetSize - offsetPosition);<br> path.lineTo(halfWidth + offsetSize, halfHeight / 2 - offsetPosition);<br> canvas.drawPath(path, paintDirection);<br> <br> //右<br> if(pressDirectionH == PtzAction.Direction.Right)<br> paintDirection.setColor(Color.parseColor("#0000ff"));<br> else<br> paintDirection.setColor(Color.parseColor("#ffffff"));<br> <br> path.reset();<br> path.moveTo(halfWidth + halfWidth / 2 + offsetPosition, halfHeight - offsetSize);<br> path.lineTo(halfWidth + halfWidth / 2 + offsetPosition + offsetSize, halfHeight);<br> path.lineTo(halfWidth + halfWidth / 2 + offsetPosition, halfHeight + offsetSize);<br> canvas.drawPath(path, paintDirection);<br> <br> //下<br> if(pressDirectionV == PtzAction.Direction.Down)<br> paintDirection.setColor(Color.parseColor("#0000ff"));<br> else<br> paintDirection.setColor(Color.parseColor("#ffffff"));<br> <br> path.reset();<br> path.moveTo(halfWidth - offsetSize, halfHeight + halfHeight / 2 + offsetPosition);<br> path.lineTo(halfWidth, halfHeight + halfHeight / 2 + offsetSize + offsetPosition);<br> path.lineTo(halfWidth + offsetSize, halfHeight + halfHeight / 2 + offsetPosition);<br> canvas.drawPath(path, paintDirection);<br> <br> //左<br> if(pressDirectionH == PtzAction.Direction.Left)<br> paintDirection.setColor(Color.parseColor("#0000ff"));<br> else<br> paintDirection.setColor(Color.parseColor("#ffffff"));<br> <br> path.reset();<br> path.moveTo(halfWidth / 2 - offsetPosition, halfHeight - offsetSize);<br> path.lineTo(halfWidth / 2 - offsetPosition - offsetSize, halfHeight);<br> path.lineTo(halfWidth / 2 - offsetPosition, halfHeight + offsetSize);<br> canvas.drawPath(path, paintDirection);<br> } |
以上就是直播商城系统源码,自定义View实现方向控制控件,可拖拽中间圆, 更多内容欢迎关注之后的文章
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· 分享一个免费、快速、无限量使用的满血 DeepSeek R1 模型,支持深度思考和联网搜索!
· 基于 Docker 搭建 FRP 内网穿透开源项目(很简单哒)
· ollama系列01:轻松3步本地部署deepseek,普通电脑可用
· 25岁的心里话
· 按钮权限的设计及实现
2022-08-02 搭建直播平台,使用node生成验证码图片,并进行验证
2022-08-02 直播系统搭建,vue 列表无缝实时滚动
2022-08-02 直播app开发搭建,vue无白屏刷新
2021-08-02 定制开发小游戏,ionic-angular左滑展示操作按钮
2021-08-02 小游戏APP源码,带头部可折叠的ListVivew
2021-08-02 成品小游戏源码,FairyGUI-GSlider滑动条