Canvas 实现四个扇形组成的圆,点击或触摸时,点在哪个扇形里,绘制扇形渐变背景色

实现以下效果:

1. 实现一个圆形;

2. 在圆形上绘制4个扇形;

3. 每个扇形点击时,是一种颜色;非点击时,是一种颜色;

4.长按扇形时,出现长按的背景;

代码逻辑:

核心代码:

1 . Brush.radialGradient  绘制渐变

2. drawArc  绘制扇形;

3.  .pointerInput(Unit) { detectTapGestures()} 监听触摸点击事件;处理触摸点在哪个扇形里面;

var selectedSegment by remember { mutableIntStateOf(-1) }
val colorItem = colorResource(id = R.color.xxxx)
val angles = listOf(45f, 135f, 225f, 315f)

val colorList = listOf(colorResource(id = R.color.xxxx), colorResource(id = R.color.xxxx),colorResource(id = R.color.xxxx), colorResource(id = R.color.xxx) )
Box(
    modifier = Modifier.size(300.dp)
        .background(colorResource(id = R.color.xxx), shape = CircleShape),
    contentAlignment = Alignment.Center
) {
    Canvas(
        modifier = Modifier.fillMaxSize()
     
  • 15
    点赞
  • 11
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值