HarmonyOS 如何绘制实心圆,DrawingRenderingContext可以吗?

HarmonyOS 如何绘制实心圆,DrawingRenderingContext可以吗?

HarmonyOS
2024-11-27 10:27:06
浏览
收藏 0
回答 1
回答 1
按赞同
/
按时间
put_get

参考代码:

@Entry 
@Component 
struct CircleByOneHeart { 
  @State currentCenterColor: string = '蓝色' 
  @State currentUpColor: string = '蓝色' 
  @State currentDownColor: string = '蓝色' 
  @State currentLeftColor: string = '蓝色' 
  @State currentRightColor: string = '蓝色' 
  private countDown: number = 0; //设置一个flag,用来接受定时器,可以看作定时器实体 
 
  aboutToDisappear(): void { 
    clearTimeout(this.countDown) //销毁定时器 
  } 
 
  build() { 
    Row() { 
      Column({ space: 100 }) { 
        //画一个直径为90的同心圆 
        Column() { 
          Line({ 
            //上 
            width: 10, 
            height: 20 
          }) 
            .startPoint([5, 0]) 
            .endPoint([5, 20]) 
            .strokeWidth(10) 
            .position({ x: 45, y: 5 }) 
            .stroke(this.currentUpColor == '蓝色' ? Color.Blue : Color.Red) 
            .onClick(() => { 
              if (this.currentUpColor == '蓝色') { 
                this.currentUpColor = '红色' 
              } else { 
                this.currentUpColor = '蓝色' 
              } 
              this.countDown = setTimeout(() => { 
                this.currentUpColor = '蓝色' 
              }, TimeSetting.stayTime) //设置定时器时间以及处理事件 
            }) 
          Line({ 
            //下 
            width: 10, 
            height: 20 
          }) 
            .startPoint([5, 0]) 
            .endPoint([5, 20]) 
            .strokeWidth(10) 
            .position({ x: 45, y: 75 }) 
            .stroke(this.currentDownColor == '蓝色' ? Color.Blue : Color.Red) 
            .onClick(() => { 
              if (this.currentDownColor == '蓝色') { 
                this.currentDownColor = '红色' 
              } else { 
                this.currentDownColor = '蓝色' 
              } 
              this.countDown = setTimeout(() => { 
                this.currentDownColor = '蓝色' 
              }, TimeSetting.stayTime) //设置定时器时间以及处理事件 
            }) 
          Line({ 
            //左 
            width: 20, 
            height: 10 
          }) 
            .startPoint([0, 5]) 
            .endPoint([20, 5]) 
            .strokeWidth(10) 
            .position({ x: 5, y: 45 }) 
            .stroke(this.currentLeftColor == '蓝色' ? Color.Blue : Color.Red) 
            .onClick(() => { 
              if (this.currentLeftColor == '蓝色') { 
                this.currentLeftColor = '红色' 
              } else { 
                this.currentLeftColor = '蓝色' 
              } 
              this.countDown = setTimeout(() => { 
                this.currentLeftColor = '蓝色' 
              }, TimeSetting.stayTime) //设置定时器时间以及处理事件 
            }) 
          Line({ 
            //右 
            width: 20, 
            height: 10 
          }) 
            .startPoint([0, 5]) 
            .endPoint([20, 5]) 
            .strokeWidth(10) 
            .position({ x: 75, y: 45 }) 
            .stroke(this.currentRightColor == '蓝色' ? Color.Blue : Color.Red) 
            .onClick(() => { 
              if (this.currentRightColor == '蓝色') { 
                this.currentRightColor = '红色' 
              } else { 
                this.currentRightColor = '蓝色' 
              } 
              this.countDown = setTimeout(() => { 
                this.currentRightColor = '蓝色' 
              }, TimeSetting.stayTime) //设置定时器时间以及处理事件 
            }) 
          Button('确定') 
            .width(50) 
            .height(50) 
            .type(ButtonType.Circle) 
            .position({ x: 25, y: 25 })//绝对定位 
            .backgroundColor(this.currentCenterColor == '蓝色' ? Color.Blue : Color.Red) 
            .onClick(() => { 
              if (this.currentCenterColor == '蓝色') { 
                this.currentCenterColor = '红色' 
              } else { 
                this.currentCenterColor = '蓝色' 
              } 
              this.countDown = setTimeout(() => { 
                this.currentCenterColor = '蓝色' 
              }, TimeSetting.stayTime) //设置定时器时间以及处理事件 
            }) 
        } 
        .width('100') 
        .height('100') 
        .backgroundColor('#ffffff') 
        .border({ 
          //border的宽度是向内的,宽度越大占用内部空间越大 
          color: Color.Blue, 
          width: 10, 
          radius: 100 
        }) 
      } 
      .width('100%') 
      .height('100%') 
      .justifyContent(FlexAlign.Center) 
    } 
    .height('100%') 
  } 
} 
 
class TimeSetting { 
  public static readonly stayTime = 300 //单位是毫秒 
}
  • 1.
  • 2.
  • 3.
  • 4.
  • 5.
  • 6.
  • 7.
  • 8.
  • 9.
  • 10.
  • 11.
  • 12.
  • 13.
  • 14.
  • 15.
  • 16.
  • 17.
  • 18.
  • 19.
  • 20.
  • 21.
  • 22.
  • 23.
  • 24.
  • 25.
  • 26.
  • 27.
  • 28.
  • 29.
  • 30.
  • 31.
  • 32.
  • 33.
  • 34.
  • 35.
  • 36.
  • 37.
  • 38.
  • 39.
  • 40.
  • 41.
  • 42.
  • 43.
  • 44.
  • 45.
  • 46.
  • 47.
  • 48.
  • 49.
  • 50.
  • 51.
  • 52.
  • 53.
  • 54.
  • 55.
  • 56.
  • 57.
  • 58.
  • 59.
  • 60.
  • 61.
  • 62.
  • 63.
  • 64.
  • 65.
  • 66.
  • 67.
  • 68.
  • 69.
  • 70.
  • 71.
  • 72.
  • 73.
  • 74.
  • 75.
  • 76.
  • 77.
  • 78.
  • 79.
  • 80.
  • 81.
  • 82.
  • 83.
  • 84.
  • 85.
  • 86.
  • 87.
  • 88.
  • 89.
  • 90.
  • 91.
  • 92.
  • 93.
  • 94.
  • 95.
  • 96.
  • 97.
  • 98.
  • 99.
  • 100.
  • 101.
  • 102.
  • 103.
  • 104.
  • 105.
  • 106.
  • 107.
  • 108.
  • 109.
  • 110.
  • 111.
  • 112.
  • 113.
  • 114.
  • 115.
  • 116.
  • 117.
  • 118.
  • 119.
  • 120.
  • 121.
  • 122.
  • 123.
  • 124.
  • 125.
  • 126.
  • 127.
  • 128.
  • 129.
  • 130.
  • 131.
  • 132.
  • 133.
  • 134.
  • 135.
  • 136.
  • 137.
分享
微博
QQ
微信
回复
2024-11-27 15:06:44
相关问题
HarmonyOS drawCircle画空心实心
510浏览 • 1回复 待解决
HarmonyOS 如何根据圆心坐标画实心
449浏览 • 1回复 待解决
HarmonyOS 根据圆心坐标绘制问题
575浏览 • 1回复 待解决
har包不能用worker,taskpool可以吗
2930浏览 • 1回复 待解决
如果不设置,可以吗
4996浏览 • 1回复 待解决
HarmonyOS 如何绘制原生组件
499浏览 • 1回复 待解决
HarmonyOS 绘制圆滑折线或绘制曲线
782浏览 • 1回复 待解决
HarmonyOS 绘制水印如何实现?
786浏览 • 1回复 待解决