HarmonyOS 如何点击让两个view展开,收起

HarmonyOS
2024-12-25 08:41:59
3213浏览
收藏 0
回答 1
回答 1
按赞同
/
按时间
Heiang

参考示例如下:

import { curves, window } from '@kit.ArkUI';
@Entry
@Component
struct PageAnimationTwoRow {
  @State isExpand: boolean = false;

  aboutToAppear(): void {
    window.getLastWindow(getContext(this)).then((win) => {
      win.setPreferredOrientation(window.Orientation.LANDSCAPE)
    })
  }

  build() {
    Flex({ justifyContent: FlexAlign.Center, alignItems: ItemAlign.Center }) {
      Row() {
        Text("颜色")
        Text(this.isExpand ?
          `点
击
收
起`:
          `查
看
词
意`)
          .onClick(() => {
            animateTo({ duration: 500 }, () => {
              this.isExpand = !this.isExpand
            })
          })
          .position({
            left: this.isExpand ? 400 : 200,
            top: 20
          })
          .backgroundColor("#ffe2af5b")
          .fontColor("#fff")
          .padding(5)
          .borderRadius({
            topRight: 10, bottomRight: 10
          })
      }
      .width(200)
      .height(200)
      .backgroundColor("#ffffffff")
      .border({ width: 8, color: "#ffe2a478" })
      .borderRadius(10)
      .zIndex(2)

      Row() {
        Row() {
          Text("Colors")
        }.rotate({
          angle: this.isExpand ? 0 : -2
        })
      }
      .rotate({
        angle: this.isExpand ? 0 : 2
      })
      .width(200)
      .height(200)
      .backgroundColor("#ffffffff")
      .border({ width: 8, color: "#ffe2a478" })
      .borderRadius(10)
      .margin({ left: this.isExpand ? -0 : -200 })
      .zIndex(1)
      .animation({
        duration: 500
      })
    }.width("100%").height("100%").backgroundColor("#ffe7d5a5").padding(10)
  }
}
  • 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.
分享
微博
QQ
微信
回复
2024-12-25 10:57:20
相关问题
HarmonyOS 怎么两个list同时滚动
733浏览 • 1回复 待解决
如何Swiper在一屏中显示两个Item?
2216浏览 • 1回复 待解决
HarmonyOS 如何合并两个对象
957浏览 • 1回复 待解决
如何实现文本展开收起功能
1457浏览 • 1回复 待解决
HarmonyOS 两个日期怎么比较
1215浏览 • 1回复 待解决
HarmonyOS 如何两个对象进行排序
840浏览 • 1回复 待解决
HarmonyOS 如何比较两个日期的大小?
1502浏览 • 1回复 待解决
HarmonyOS 两个同级的组件问题
1266浏览 • 1回复 待解决
两个设备控制相关问题
9603浏览 • 3回复 已解决
HarmonyOS 关于两个权限的区别
1280浏览 • 1回复 待解决
HarmonyOS 两个网页间的数据如何同步
618浏览 • 1回复 待解决
HarmonyOS 怎么把两个PixelMap合成一
1211浏览 • 2回复 待解决
HarmonyOS 两个List互相锚点功能
576浏览 • 1回复 待解决
HarmonyOS ets文件,合并两个Record记录
1824浏览 • 1回复 待解决