【鸿蒙】HarmonyOS NEXT星河入门到实战4-ArkTS界面布局深入

news2024/9/21 11:08:26

目录

一、布局元素组成

1.1 内边距-padding

1.2 外边距 margin

1.3 实战案例-QQ音乐-登录

1.4 边框 border

 二、设置组件圆角

2.1 基本圆角设置

2.2 特殊形状的圆角设置

三、背景属性

3.1 背景图片-backgroundImage

3.2 背景图片位置-backgroundImagePosition

3.3 背景定位-单位问题vp2px(5.x版本忽略此问题,单位一致了)

3.4 背景尺寸大小-backgroundlmageSize

四、线性布局

4.1 主轴对齐方式

 4.2 综合案例 个人中心-顶部导航

4.3 交叉轴对齐方式

4.4 综合案例-得物列表项

4.4 自定义伸缩-layoutWeight

4.5 综合案例-得物卡片

4.6 综合案例-京东登录

五、弹性布局

5.1 主轴方向、对齐方式、交叉轴对齐方式

5.2 综合案例Flex 换行 -wrap

六、绝对定位 -position和层级zlndex

6.1 绝对定位和层级

6.2 综合案例-人气卡片案例

七、层叠布局

7.1 层叠布局示例

7.2 综合案例-B站-视频卡片

八、阶段综合练习-【支付宝】


前言:ArkTS界面布局深入讲解

一、布局元素组成

1.1 内边距-padding

@Entry
@Component
struct Index {
  @State message: string = '春天的菠菜';

  build() {
     Column(){
       Text('王语嫣')
         .backgroundColor(Color.Pink)
         .padding(10)// 四个方向设置相同的内边距
       Text('杨过')
         .backgroundColor(Color.Green)
         .padding({
           left: 20,
           top: 30,
           right: 5,
           bottom: 30
         })//分别设置

    }

  }
}

1.2 外边距 margin

@Entry
@Component
struct Index {
  @State message: string = '春天的菠菜';

  build() {
     Column(){
       Row(){
         Text('刘备')
           .backgroundColor(Color.Orange)
         Text('关羽')
           .backgroundColor(Color.Pink)
           .margin({
             left: 30,
             right: 30
           })
         Text('张飞')
           .backgroundColor(Color.Green)
       }

       Column(){
         Text('刘备')
           .backgroundColor(Color.Orange)
         Text('关羽')
           .backgroundColor(Color.Pink)
           .margin({
             top: 30,
             bottom: 30
           })
         Text('张飞')
           .backgroundColor(Color.Green)
       }


    }

  }
}

1.3 实战案例-QQ音乐-登录

@Entry
@Component
struct Index {
  @State message: string = '春天的菠菜';

  build() {
     Column(){
       Image($r('app.media.m_user'))
         .width('100')
       Text('女子交友俱乐部')
         .fontWeight(700)
         .margin({
           top: 10,
           bottom: 40
         })
       Button('QQ登录')
         .width('100%')
         .margin({
           bottom: 10
         })
       Button('微信登录')
         .width('100%')
         .backgroundColor('#ddd')
         .fontColor('#000')

    }
    .padding(20)
    .width('100%')

  }
}

1.4 边框 border

@Entry
@Component
struct Index {
  @State message: string = '春天的菠菜';

  build() {
     Column(){
       Text('待完善')
         .fontColor(Color.Red)
         .padding(5)
         .border({
           width: 1,  // 宽度(必须)
           color: Color.Red,
           style: BorderStyle.Dashed  // 样式(Dashed   虚线 Solid  实线(默认) Dotted 点线)
         })
         .margin({bottom: 20})

       Text('单边框')
         .padding(5)
         .border({
           width: {left: 1, right: 2},
           color: {left: Color.Blue, right:  Color.Green},
           style: {left: BorderStyle.Dotted, right: BorderStyle.Solid}
         })
    }
    .padding(20)
    // .width('100%')

  }
}

 二、设置组件圆角

2.1 基本圆角设置

import { TextReaderIcon } from '@hms.ai.textReader';

@Entry
@Component
struct Index {
  @State message: string = '春天的菠菜';

  build() {
     Column(){
       Text('没有圆角')
         .width(100)
         .height(60)
         .backgroundColor(Color.Pink)
         .margin({bottom: 30})
       Text('相同圆角')
         .width(100)
         .height(60)
         .backgroundColor(Color.Gray)
         .margin({bottom: 30})
         .borderRadius(15) // 设置相同的圆角
       Text('不同圆角')
         .width(100)
         .height(60)
         .backgroundColor(Color.Green)
         .borderRadius({
           topLeft: 10,
           topRight:2,
           bottomLeft: 20,
           bottomRight: 30
         }) // 设置不同的圆角
    }
    .padding(20)
    // .width('100%')

  }
}

2.2 特殊形状的圆角设置

 

@Entry
@Component
struct Index {
  @State message: string = '春天的菠菜';

  build() {
    Column(){
      // 1 正圆
      Image($r('app.media.cat'))
        .width(100)
        .height(100)
        .borderRadius(50)
        .margin({bottom: 5})
      // 2 胶囊按钮
      Text('胶囊按钮效果与文本长有关')
        .height(50)
        .borderRadius(25)  //高的一半
        .backgroundColor(Color.Pink)
        .padding(10)
    }
    .padding(20)
    // .width('100%')

  }
}

三、背景属性

3.1 背景图片-backgroundImage

 

@Entry
@Component
struct Index {
  @State message: string = '春天的菠菜';

  build() {
    Column(){
      Text('中山大道')
        .fontColor(Color.White)
        .width(200)
        .height(100)
        .backgroundColor(Color.Pink)
        .backgroundImage($r('app.media.flower'))
        .margin({bottom: 5})


      Text('背景图片平铺图')
        .fontColor(Color.White)
        .width(200)
        .height(200)
        .backgroundColor(Color.Pink)
        .backgroundImage($r('app.media.flower'),ImageRepeat.XY) // xy水平与垂直平铺 
    }
    .padding(20)
    // .width('100%')

  }
}

3.2 背景图片位置-backgroundImagePosition

@Entry
@Component
struct Index {
  @State message: string = '春天的菠菜';

  build() {
    Column(){
      Text()       
        .width(300)
        .height(200)
        .backgroundColor(Color.Pink)
        .backgroundImage($r('app.media.flower'))
        .backgroundImagePosition({x: 50, y: 50}) // 坐标方式
        .margin({bottom: 5})
      Text()
        .fontColor(Color.White)
        .width(300)
        .height(200)
        .backgroundColor(Color.Pink)
        .backgroundImage($r('app.media.flower'))
        .backgroundImagePosition(Alignment.Center)// 方式二 枚举
    }
    .padding(20)
    // .width('100%')

  }
}

3.3 背景定位-单位问题vp2px(5.x版本忽略此问题,单位一致了)

@Entry
@Component
struct Index {
  @State message: string = '春天的菠菜';

  build() {
    Column(){
      Text()
        .width(300)
        .height(200)
        .backgroundColor(Color.Pink)
        .backgroundImage($r('app.media.flower'))
        .backgroundImagePosition({
          x:  vp2px(150), //新版5.X 直接150
          y: vp2px(100), //新版5.X 直接100
        })

    }
    .padding(20)
    // .width('100%')

  }
}

使用5.X版本,发现花不见了,原来新版本单位已经一致了,无需vp2px

3.4 背景尺寸大小-backgroundlmageSize

@Entry
@Component
struct Index {
  @State message: string = '春天的菠菜';
  build() {
    Column(){
      Text()
        .width(300)
        .height(200)
        .backgroundColor(Color.Green)
        .backgroundImage($r('app.media.jd_bj3'))
        .backgroundImagePosition(Alignment.Center)
        .backgroundImageSize(ImageSize.Cover)  //ImageSize.Contain
        // .backgroundImageSize({
        //   width:300,
        //   height: 200
        // })

    }
    .padding(20)
    // .width('100%')
  }
}

四、线性布局

4.1 主轴对齐方式

@Entry
@Component
struct Index {
  @State message: string = '春天的菠菜';
  build() {
    Column(){ 
      Text()
        .width(200)
        .height(100)
        .backgroundColor(Color.Green)
        .border({width: 2})
      Text()
        .width(200)
        .height(100)
        .backgroundColor(Color.Green)
        .border({width: 2})
        .margin(5)
      Text()
        .width(200)
        .height(100)
        .backgroundColor(Color.Green)
        .border({width: 2})

    }

    .width('100%')
    .height('100%')
    .backgroundColor('#ccc')
  //   设置排布主方向的对齐方式(主轴) ctrl + p
  //   Row()方法类似 这里省略
    .justifyContent(FlexAlign.SpaceAround)
  }
}

 4.2 综合案例 个人中心-顶部导航

import window from '@ohos.window';
@Entry
@Component
struct Index {
  @State message: string = '春天的菠菜';

  onPageShow(): void {
    window.getLastWindow(AppStorage.get("context"), (err, data) => {
      if (err.code) {
        console.error('Failed to get last window. Cause:' + JSON.stringify(err));
        return;
      }
      data.setFullScreen(true)
    });
  }
  build() {
    Column(){
      Row(){
        Image($r('app.media.ic_arrow_left'))
          .width(30)
        Text('个人中心')
        Image($r('app.media.ic_more'))
          .width(24)
      }
      .justifyContent(FlexAlign.SpaceBetween)
      .width('100%')
      .height(40)
      .backgroundColor(Color.White)
      .padding({left: 10,right: 10})

    }

    .width('100%')
    .height('100%')
    .backgroundColor('#ccc')

  }
}

4.3 交叉轴对齐方式

import window from '@ohos.window';
@Entry
@Component
struct Index {
  @State message: string = '春天的菠菜';

  onPageShow(): void {
    window.getLastWindow(AppStorage.get("context"), (err, data) => {
      if (err.code) {
        console.error('Failed to get last window. Cause:' + JSON.stringify(err));
        return;
      }
      data.setFullScreen(true)
    });
  }
  build() {
    Column(){
      Text()
        .width(200)
        .height(100)
        .backgroundColor(Color.Green)
        .border({width: 2})
      Text()
        .width(200)
        .height(100)
        .backgroundColor(Color.Green)
        .border({width: 2})
        .margin({top: 5,bottom: 5})
      Text()
        .width(200)
        .height(100)
        .backgroundColor(Color.Green)
        .border({width: 2})

    }

    .width('100%')
    .height('100%')
    .backgroundColor('#ccc')
    .alignItems(HorizontalAlign.Start)  // Row的交叉轴 垂直对齐方式  VerticalAlign.End 
  }
}

4.4 综合案例-得物列表项

import window from '@ohos.window';
@Entry
@Component
struct Index {
  @State message: string = '春天的菠菜';

  onPageShow(): void {
    window.getLastWindow(AppStorage.get("context"), (err, data) => {
      if (err.code) {
        console.error('Failed to get last window. Cause:' + JSON.stringify(err));
        return;
      }
      data.setFullScreen(true)
    });
  }
  build() {
    Column(){
      Row(){
        // 左侧列
        Column({ space: 8 }){
          Text('玩一玩')
            .fontSize(18)
            .fontWeight(700)
          Text('签到兑礼 | 超多大奖 超好玩')
            .fontSize(12)
            .fontColor('#999')
        }
        .alignItems(HorizontalAlign.Start) // 交叉轴对齐方式
        // 右侧列
        Row({ space: 8 }){
          Image($r('app.media.tree'))
            .width(50)
            .backgroundColor('#efefef')
            .borderRadius(5)
          Image($r('app.media.ic_arrow_right'))
            .width(20)
            .fillColor('#999')
        }
      }
      .justifyContent(FlexAlign.SpaceBetween)
      .padding({left: 15,right:15})
      .width('100%')
      .height(80)
      .backgroundColor('#fff')
      .borderRadius(5)
    }
    .padding(10)
    .width('100%')
    .height('100%')
    .backgroundColor('#ccc')

  }
}

4.4 自定义伸缩-layoutWeight

import window from '@ohos.window';
@Entry
@Component
struct Index {
  @State message: string = '春天的菠菜';

  onPageShow(): void {
    window.getLastWindow(AppStorage.get("context"), (err, data) => {
      if (err.code) {
        console.error('Failed to get last window. Cause:' + JSON.stringify(err));
        return;
      }
      data.setFullScreen(true)
    });
  }
  build() {
    Column(){
    // LayoutWeight
      Row(){
      //   左侧
        Text('左侧')
          .layoutWeight(1)
          .backgroundColor(Color.Green)
          .height(40)

      //   右侧
        Text('右侧固定')
          .width(80)
          .height(40)
          .backgroundColor(Color.Orange)
      }
      .width(300)
      .height(40)
      .backgroundColor('#fff')

      // LayoutWeight 多个对象
      Row(){
        //   老大
        Text('老大')
          .layoutWeight(1)
          .backgroundColor(Color.Green)
          .height(40)
        //   老二
        Text('老二')
          .layoutWeight(2)
          .width(80)
          .height(40)
          .backgroundColor(Color.Pink)
        //   老三
        Text('老三')
          .width(80)
          .height(40)
          .backgroundColor(Color.Orange)
      }
      .width(300)
      .height(40)
      .backgroundColor('#fff')
      .margin({top: 30})

    }
    .padding(10)
    .width('100%')
    .height('100%')
    .backgroundColor('#ccc')

  }
}

4.5 综合案例-得物卡片

import window from '@ohos.window';
@Entry
@Component
struct Index {
  @State message: string = '春天的菠菜';

  onPageShow(): void {
    window.getLastWindow(AppStorage.get("context"), (err, data) => {
      if (err.code) {
        console.error('Failed to get last window. Cause:' + JSON.stringify(err));
        return;
      }
      data.setFullScreen(true)
    });
  }
  build() {
    Column(){
      Column(){
        Image($r('app.media.nick'))
          .width('100%')
          .borderRadius({topLeft: 5, topRight: 5})
        Text('今晚吃这个 | 每日艺术分享 No. 43')
          .fontWeight(600)
          .fontSize(14)
          .lineHeight(22)
          .height(60)
      //   底部
        Row(){
          //  底部左侧
          Row({space: 5}){
            Image($r('app.media.user'))
              .height(16)
              .borderRadius(8)
            Text('插画师分享聚集地')
              .fontSize(10)
              .fontColor('#999')

          }
          .layoutWeight(1)
          //底部右侧
          Row({space: 5}){
            Image($r('app.media.ic_like'))
              .width(12)
              .fillColor('#999')
            Text('2300')
              .fontSize(10)
              .fontColor('#666')
          }

        }
        .padding({left: 15,right: 15})

      }
      .width(200)
      .padding({bottom: 15})
      // .height(400) // 设计时先固定高,设计完成去掉
      .backgroundColor(Color.White)
      .borderRadius(5)


    }
    .padding(10)
    .width('100%')
    .height('100%')
    .backgroundColor('#ccc')

  }
}

 

4.6 综合案例-京东登录

 

import window from '@ohos.window';
@Entry
@Component
struct Index {
  @State message: string = '春天的菠菜';

  onPageShow(): void {
    window.getLastWindow(AppStorage.get("context"), (err, data) => {
      if (err.code) {
        console.error('Failed to get last window. Cause:' + JSON.stringify(err));
        return;
      }
      data.setFullScreen(true)
    });
  }
  build() {
    Column(){
    //   顶部区域
      Row(){
        Image($r('app.media.jd_cancel'))
          .width(20)
        Text('帮助')
      }
      .width('100%')
      .justifyContent(FlexAlign.SpaceBetween)

    //   Logo
      Image($r('app.media.jd_logo'))
        .width(250)
        .height(250)
   // 国家地址区域
      Row(){
        Text('国家/地址')
          .layoutWeight(1)
          .fontColor('#666')
        Text('中国(+86)')
          .margin({right: 5})
          .fontColor('#666')
        Image($r('app.media.jd_right'))
          .width(20)
          .fillColor('#666')

      }
      .width('100%')
      .height(40)
      .backgroundColor('#fff')
      .borderRadius(20)
      .padding({left: 15, right:10})

    //   手机号(输入框)
      TextInput({
        placeholder: '请输入手机号'
      })
        .height(40)
        .borderRadius(20)
        .backgroundColor('#fff')
        .margin({top: 20})
        .placeholderColor('#666')

    //   已阅读并同意
      Row(){
        Checkbox()
          .width(10)
          .margin({top: 7})
        // 一段文本中,有文本样式需要单独定制,TEXT 包括SPAN
        Text(){
          Span('我已阅读并同意')
          Span('《京东隐私政策》').fontColor('#3274f6')
          Span('《京东用户服务协议》').fontColor('#3274f6')
          Span('未注册的手机号将自动创建京东账号')
        }
        .fontSize(12)
        .fontColor('#666')
        .lineHeight(20)

      }
      .alignItems(VerticalAlign.Top)
      .margin({top: 20})

    //  登录
      Button('登录')
        .width('100%')
        .backgroundColor('#bf2838')
        .margin({top: 25})

    //   新用户注册等
      Row({ space: 25 }){
        Text('新用户注册').fontSize(14).foregroundColor('#666')
        Text('账户密码登录').fontSize(14).foregroundColor('#666')
        Text('无法登录').fontSize(14).foregroundColor('#666')
      }
      .margin({top: 15})
      // 填充组件Black() 作用 填充空白区域
      Blank()
      // 底部其他登录方式
      Column(){
        Text('其他登录方式')
          .fontColor('#666')
          .height(22)
          .fontSize(14)
          .margin({bottom: 28})
        Row(){
          Image($r('app.media.jd_huawei')).width(34)
          Image($r('app.media.jd_wechat')).width(34).fillColor('#56a44a')
          Image($r('app.media.jd_weibo')).width(34).fillColor('#c8493b')
          Image($r('app.media.jd_QQ')).width(34).fillColor('#4ba0e8')

        }
        .width('100%')
        .margin({bottom: 30})
        .justifyContent(FlexAlign.SpaceAround)

      }
      .width('100%')
      // .backgroundColor(Color.Pink)

    }
    .padding(20)
    .width('100%')
    .height('100%')
    .backgroundColor(Color.Pink)
    .backgroundImage($r('app.media.jd_login_bg'))
    .backgroundImageSize(ImageSize.Cover)

  }
}

五、弹性布局

5.1 主轴方向、对齐方式、交叉轴对齐方式

import window from '@ohos.window';
@Entry
@Component
struct Index {
  @State message: string = '春天的菠菜';

  onPageShow(): void {
    window.getLastWindow(AppStorage.get("context"), (err, data) => {
      if (err.code) {
        console.error('Failed to get last window. Cause:' + JSON.stringify(err));
        return;
      }
      data.setFullScreen(true)
    });
  }
  build() {
    // Flex默认是主轴,水平往右,交叉轴是垂直往下 (跟我们Row相似)
    // 1、 主轴方向
    // direction: FlexDirection.Column  / Row   // 改变主轴方向 {direction: FlexDirection.Column} 改成垂直往下
    // 2、 主轴对齐方式
    // justifyContent: FlexAlign.SpaceAround
    // 3、交叉轴对齐方式
    // alignItems: ItemAlign.End

    Flex({direction: FlexDirection.Row,
      justifyContent: FlexAlign.SpaceAround,
      alignItems: ItemAlign.End

    }){

      Text()
        .width(80).height(80)
        .backgroundColor(Color.Pink)
        .border({width: 1, color: Color.Blue})
      Text()
        .width(80).height(80)
        .backgroundColor(Color.Pink)
        .border({width: 1, color: Color.Blue})
      Text()
        .width(80).height(80)
        .backgroundColor(Color.Pink)
        .border({width: 1, color: Color.Blue})
    }
    .width('100%').height(600)
    .backgroundColor('#5f9a5c')



  }
}

5.2 综合案例Flex 换行 -wrap

import window from '@ohos.window';
@Entry
@Component
struct Index {
  @State message: string = '春天的菠菜';

  onPageShow(): void {
    window.getLastWindow(AppStorage.get("context"), (err, data) => {
      if (err.code) {
        console.error('Failed to get last window. Cause:' + JSON.stringify(err));
        return;
      }
      data.setFullScreen(true)
    });
  }
  build() {
    Column(){
      Text('阶段选择')
        .fontSize(30)
        .fontWeight(700)
        .padding(15)
        .width('100%')
      Flex({
        wrap: FlexWrap.Wrap
      }){
        Text('ArkUI').margin(5).padding(10).backgroundColor('#f1f1f1')
        Text('ArkTS').margin(5).padding(10).backgroundColor('#f1f1f1')
        Text('界面开发').margin(5).padding(10).backgroundColor('#f1f1f1')
        Text('系统能力').margin(5).padding(10).backgroundColor('#f1f1f1')
        Text('权限控制').margin(5).padding(10).backgroundColor('#f1f1f1')
        Text('元服务').margin(5).padding(10).backgroundColor('#f1f1f1')
      }
    }

  }
}

六、绝对定位 -position和层级zlndex

6.1 绝对定位和层级

import window from '@ohos.window';
@Entry
@Component
struct Index {
  @State message: string = '春天的菠菜';

  onPageShow(): void {
    window.getLastWindow(AppStorage.get("context"), (err, data) => {
      if (err.code) {
        console.error('Failed to get last window. Cause:' + JSON.stringify(err));
        return;
      }
      data.setFullScreen(true)
    });
  }
  build() {
    Column(){
      Text('张三').width(80).height(80).backgroundColor(Color.Green)
      Text('李四').width(80).height(80).backgroundColor(Color.Yellow)
        .position({ //绝对定位
          x: 50,
          y: 50
        })
        .zIndex(1) //层级
      Text('王二').width(80).height(80).backgroundColor(Color.Orange)

    }
   .width(300).height(300)
    .backgroundColor(Color.Pink)
  }
}

6.2 综合案例-人气卡片案例

import window from '@ohos.window';
@Entry
@Component
struct Index {
  @State message: string = '春天的菠菜';

  onPageShow(): void {
    window.getLastWindow(AppStorage.get("context"), (err, data) => {
      if (err.code) {
        console.error('Failed to get last window. Cause:' + JSON.stringify(err));
        return;
      }
      data.setFullScreen(true)
    });
  }
  build() {
    Column(){
    // 先整体 再局部 再细节
      Column(){
        // 定位 的VIP
        Text('VIP')
          .position({
            x: 0,
            y: 0
          })
          .zIndex(666)
          .width(40).height(20)
          .backgroundColor('#e49642')
          .borderRadius({
            topLeft: 10,
            bottomRight: 10
          })
          .border({width: 2,color: '#fbe7a3'})
          .fontColor('#fbe7a3')
          .fontStyle(FontStyle.Italic)
          .fontSize(14).fontWeight(700)
          .textAlign(TextAlign.Center) // 文本对齐方式  或者使用 .padding({left: 5})


        // 上图
        Image($r('app.media.position_moco'))
          .width('100%').height(210)
          .borderRadius(10)

      //   下row 图+文本
        Row(){
          Image($r('app.media.position_earphone'))
            .width(20)
            .backgroundColor('#55b7f4')
            .borderRadius(10)
            .padding(3)
            .fillColor(Color.White)
            .margin({left: 6, right: 6})
          Text('飞狗MOCO')
            .fontWeight(700)

        }
        .width('100%').height(30)
        // .backgroundColor(Color.Orange)


      }
      .width(160).height(240)
      .backgroundColor(Color.White)

    }
    .width('100%')
    .height('100%')
    .backgroundColor(Color.Pink)
  }
}

七、层叠布局

7.1 层叠布局示例

import window from '@ohos.window';
@Entry
@Component
struct Index {
  @State message: string = '春天的菠菜';

  onPageShow(): void {
    window.getLastWindow(AppStorage.get("context"), (err, data) => {
      if (err.code) {
        console.error('Failed to get last window. Cause:' + JSON.stringify(err));
        return;
      }
      data.setFullScreen(true)
    });
  }
  build() {
    // 层叠布局
    Stack({
      alignContent: Alignment.Bottom  // 改变位置
    }){
      Text('刘备')
        .width(250).height(250)
        .backgroundColor(Color.Pink)
      Text('关羽')
        .width(150).height(150)
        .backgroundColor(Color.Orange)
      Text('张飞')
        .width(50).height(50)
        .backgroundColor(Color.Yellow)


    }
    .width(300).height(600)
    .backgroundColor(Color.Green)

  }
}

7.2 综合案例-B站-视频卡片

import window from '@ohos.window';
@Entry
@Component
struct Index {
  @State message: string = '春天的菠菜';

  onPageShow(): void {
    window.getLastWindow(AppStorage.get("context"), (err, data) => {
      if (err.code) {
        console.error('Failed to get last window. Cause:' + JSON.stringify(err));
        return;
      }
      data.setFullScreen(true)
    });
  }
  build() {

    Column(){
      Column(){
        //  上面图片区域(层叠使用)
        Stack({alignContent: Alignment.Bottom }){
          Image($r('app.media.bz_img'))
            .borderRadius({
              topLeft: 10,
              topRight:10
            })
          Row(){
            Row({space: 5}){
              Image($r('app.media.bz_play'))
                .width(14)
                .fillColor(Color.White)
              Text('288万')
                .fontSize(12)
                .fontColor(Color.White)
            }
            .margin({right: 10})
            Row({space: 5}){
              Image($r('app.media.bz_msg'))
                .width(14)
                .fillColor(Color.White)
              Text('8655')
                .fontSize(12)
                .fontColor(Color.White)
            }
            Blank()
            Text('4:33')
              .fontSize(12)
              .fontColor(Color.White)


          }
          .width('100%').height(24)
          .padding({left: 5, right: 5})
          // .backgroundColor(Color.Orange)

        }
        .width('100%').height(125)
        Column(){
          Text('【凤凰传奇新歌】 还原来到国风统治区:唢呐一响神曲《铁衣》,歌声送到了海内外')
            .fontSize(13)
            .lineHeight(16)
            .textOverflow({overflow:TextOverflow.Ellipsis})
            .maxLines(2)
          Row(){
            Text('19万点赞')
              .fontSize(10)
              .fontColor('#e66c43')
              .backgroundColor('#faf0ef')
              .padding(5)
              .borderRadius(2)
            Image($r('app.media.bz_more'))
              .width(14)
          }
          .margin({top: 6})
          .width('100%')
          .justifyContent(FlexAlign.SpaceBetween)
        }
        .padding(5)


      }
      .width(200).height(200)
      .backgroundColor(Color.White)
      .borderRadius(10)
      .margin({top: 10})



    }
    .width('100%').height('100%')
    .backgroundColor('#ccc')

  }
}

八、阶段综合练习-【支付宝】

 

 

 

import window from '@ohos.window';
@Entry
@Component
struct Index {
  @State message: string = '春天的菠菜';

  onPageShow(): void {
    window.getLastWindow(AppStorage.get("context"), (err, data) => {
      if (err.code) {
        console.error('Failed to get last window. Cause:' + JSON.stringify(err));
        return;
      }
      data.setFullScreen(true)
    });
  }
  build() {
    Stack({ alignContent: Alignment.Bottom }){
    //   2 主体展示区
      Stack({alignContent: Alignment.Top}){
      //   2.1 头部
        Row(){
          // 左边
          Column(){
            Text('北京').fontSize(18).fontColor('#fff')
            Text('晴 2℃').fontSize(12).fontColor('#fff')
            Image($r('app.media.zfb_head_down'))
              .position({
                x: 40,
                y: 0
              })
              .width(12).fillColor('#fff')
          }

        //   中间
          Row(){
            Image($r('app.media.zfb_head_search'))
              .width(20)
              .fillColor('#666')
              .margin({left: 5, right: 5})
            Text('北京交通一卡通')
              .layoutWeight(1)
            Text('搜索')
              .width(55)
              .fontColor('#5b73de')
              .fontWeight(700)
              .textAlign(TextAlign.Center)
              .border({
                width: {left: 1},
                color: '#ccc'
              })


          }
          .height(32)
          .layoutWeight(1)
          .backgroundColor(Color.White)
          .borderRadius(5)
          .margin({left: 25, right: 12})

        //   右边
          Image($r('app.media.zfb_head_plus'))
            .width(30)
            .fillColor('#fff')

        }
        .width('100%').height(60)
        .backgroundColor('#5b73de')
        .zIndex(666)
        .padding({left: 10,right: 10})

      //   2.2 主体页面
     Scroll(){
       Column(){
         // TOP快捷按钮区域
        Row(){
          Column(){
            Image($r('app.media.zfb_top_scan'))
              .width(36)
              .fillColor('#fff')
            Text('扫一扫')
              .fontColor('#fff')
          }
          .layoutWeight(1)


          Column(){
            Image($r('app.media.zfb_top_pay'))
              .width(36)
              .fillColor('#fff')
            Text('收付款')
              .fontColor('#fff')
          }
          .layoutWeight(1)

          Column(){
            Image($r('app.media.zfb_top_travel'))
              .width(36)
              .fillColor('#fff')
            Text('出行')
              .fontColor('#fff')
          }
          .layoutWeight(1)


          Column(){
            Image($r('app.media.zfb_top_card'))
              .width(36)
              .fillColor('#fff')
            Text('卡包')
              .fontColor('#fff')
          }
          .layoutWeight(1)

        }
         .backgroundColor('#5b73de')
         .padding({top:5, bottom: 15})

       //   主体区 (背景色#f6f6f6
         Column(){
         //  导航区
           Column({space: 10}){
             Row(){
               Column(){
                 Image($r('app.media.zfb_nav1'))
                   .width(28).margin({bottom: 8})
                 Text('滴滴出行')
                   .fontSize(12).fontColor('#666')

               }
               .layoutWeight(1)

               Column(){
                 Image($r('app.media.zfb_nav2'))
                   .width(28).margin({bottom: 8})
                 Text('生活缴费')
                   .fontSize(12).fontColor('#666')

               }
               .layoutWeight(1)

               Column(){
                 Image($r('app.media.zfb_nav3'))
                   .width(28).margin({bottom: 8})
                 Text('股票')
                   .fontSize(12).fontColor('#666')
               }
               .layoutWeight(1)

               Column(){
                 Image($r('app.media.zfb_nav4'))
                   .width(28).margin({bottom: 8})
                 Text('蚂蚁森林')
                   .fontSize(12).fontColor('#666')
               }
               .layoutWeight(1)

               Column(){
                 Image($r('app.media.zfb_nav5'))
                   .width(28).margin({bottom: 8})
                 Text('手机充值')
                   .fontSize(12).fontColor('#666')
               }
               .layoutWeight(1)

             }
             Row(){
               Column(){
                 Image($r('app.media.zfb_nav6'))
                   .width(28).margin({bottom: 8})
                 Text('余额宝')
                   .fontSize(12).fontColor('#666')

               }
               .layoutWeight(1)

               Column(){
                 Image($r('app.media.zfb_nav7'))
                   .width(28).margin({bottom: 8})
                 Text('花呗')
                   .fontSize(12).fontColor('#666')

               }
               .layoutWeight(1)

               Column(){
                 Image($r('app.media.zfb_nav8'))
                   .width(28).margin({bottom: 8})
                 Text('飞猪旅行')
                   .fontSize(12).fontColor('#666')
               }
               .layoutWeight(1)

               Column(){
                 Image($r('app.media.zfb_nav9'))
                   .width(28).margin({bottom: 8})
                 Text('淘票票')
                   .fontSize(12).fontColor('#666')
               }
               .layoutWeight(1)

               Column(){
                 Image($r('app.media.zfb_nav10'))
                   .width(28).margin({bottom: 8})
                 Text('饿了么')
                   .fontSize(12).fontColor('#666')
               }
               .layoutWeight(1)

             }
             Row(){
               Column(){
                 Image($r('app.media.zfb_nav11'))
                   .width(28).margin({bottom: 8})
                 Text('读书听书')
                   .fontSize(12).fontColor('#666')
               }
               .layoutWeight(1)

               Column(){
                 Image($r('app.media.zfb_nav12'))
                   .width(28).margin({bottom: 8})
                 Text('基金')
                   .fontSize(12).fontColor('#666')
               }
               .layoutWeight(1)

               Column(){
                 Image($r('app.media.zfb_nav13'))
                   .width(28).margin({bottom: 8})
                 Text('直播广场')
                   .fontSize(12).fontColor('#666')
               }
               .layoutWeight(1)

               Column(){
                 Image($r('app.media.zfb_nav14'))
                   .width(28).margin({bottom: 8})
                 Text('医疗健康')
                   .fontSize(12).fontColor('#666')
               }
               .layoutWeight(1)

               Column(){
                 Image($r('app.media.zfb_nav15_more'))
                   .width(28).margin({bottom: 8})
                 Text('更多')
                   .fontSize(12).fontColor('#666')
               }
               .layoutWeight(1)

             }
           }
           .padding(10)

         //   产品区
           Row({space: 5}){
             Image($r('app.media.zfb_pro_pic1'))
               .layoutWeight(1)
             Image($r('app.media.zfb_pro_pic2'))
               .layoutWeight(1)
             Image($r('app.media.zfb_pro_pic3'))
               .layoutWeight(1)
           }
           .padding(10)

           Column({space: 10}){
             Image($r('app.media.zfb_pro_list1'))
               .width('100%')
             Image($r('app.media.zfb_pro_list2'))
               .width('100%')
           }
           .padding(10)


         }
         // .height(1000)
         .width('100%')
         .backgroundColor('#fff')
         .borderRadius({
           topLeft: 20,
           topRight: 20

         })



       }
       .width('100%')
       .padding({top: 60,bottom: 60})
     }



      }
      .width('100%').height('100%')



    //   1 底部Tab导航区
      Row(){
        Column(){
          Image($r('app.media.zfb_tab_home'))
            .width(35)

        }
        .layoutWeight(1)

        Column(){
          Image($r('app.media.zfb_tab_money'))
            .width(28)
            .margin({bottom: 2})
          Text('理财')
            .fontSize(12)

        }
        .layoutWeight(1)

        Column(){
          Image($r('app.media.zfb_tab_life'))
            .width(28)
            .margin({bottom: 2})
          Text('生活')
            .fontSize(12)

        }
        .layoutWeight(1)

        Column(){
          Image($r('app.media.zfb_tab_chat'))
            .width(28)
            .margin({bottom: 2})
          Text('消息')
            .fontSize(12)

        }
        .layoutWeight(1)

        Column(){
          Image($r('app.media.zfb_tab_me'))
            .width(28)
            .margin({bottom: 2})
          Text('我的')
            .fontSize(12)

        }
        .layoutWeight(1)

      }
      .width('100%').height(60)
      .backgroundColor('#fbfcfe')


    }
    .width('100%').height('100%')
    .backgroundColor('#5b73de')
  }
}

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.coloradmin.cn/o/2122983.html

如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈,一经查实,立即删除!

相关文章

什么是梯度? 梯度的作用 梯度的应用场景。

梯度 是一个非常重要的概念,它直接关系到模型的训练过程。以下是对梯度的详细解释: 梯度的基本概念 梯度 是一个向量,表示函数在某一点的导数或偏导数。在多维空间中,梯度指向的是函数值上升最快的方向。对于一个函数 f(x),在某一点 x 处的梯度记作 ∇f(x),它可以理解为在…

【Linux进程详解】进程地址空间

目录 1.直接写代码看现象 2.引入最基本的理解 3.细节问题-理解它 1.直接写代码看现象 #include <stdio.h> #include <string.h> #include <unistd.h> #include <stdlib.h> #include <unistd.h> int g_val 100;int main() {printf("fath…

常回家看看之house of kiwi

house of kiwi 前言&#xff1a;house_of_kiwi 一般是通过触发__malloc_assert来刷新IO流&#xff0c;最后可以劫持程序流或者通过和setcontext来打配合来进行栈迁移来得到flag。 我们看看触发的源码 #if IS_IN (libc) #ifndef NDEBUG # define __assert_fail(assertion, fi…

MFC之CString类及其成员函数用法详解

CString是 CStringT(属于MFC 和 ATL 之间共享的类) 的类模板的专用化&#xff0c;没有基类。在头文件atlstr.h中可以看到CString的定义&#xff1a; CString对象由可变长度的一队字符组成。CString是基于TCHAR数据类型的对象。如果在你的程序中定义了符号_UNICODE&#xff0c;则…

Leetcode 300. 最长递增子序列 记忆化搜索、贪心二分 C++实现

Leetcode 300. 最长递增子序列 问题&#xff1a;给你一个整数数组 nums &#xff0c;找到其中最长严格递增子序列的长度。 子序列 是由数组派生而来的序列&#xff0c;删除&#xff08;或不删除&#xff09;数组中的元素而不改变其余元素的顺序。例如&#xff0c;[3,6,2,7] 是…

猫头虎推荐:2024国内好用的PyPIP换源库

猫头虎推荐&#xff1a;2024国内好用的PyPIP换源库&#x1f525;&#x1f680; 在国内使用 Python 时&#xff0c;由于访问官方的 PyPI 速度较慢甚至无法连接&#xff0c;选择一个可靠的国内 PyPI 镜像源至关重要&#x1f4c8;。为了更高效地完成项目开发&#xff0c;今天猫头…

BC172 牛牛的排列数(c 语言)

1.我们先输入n m的数字&#xff0c;因为n!/(n-m)!的阶乘。即4&#xff01;4*3*2*1&#xff0c;2&#xff01;2*1&#xff0c;4&#xff01;/2&#xff01;12.或者4&#xff01;4*3*2&#xff01;。 #include<sdtio.h> int main() {int n 0;int m 0;long long a 1;whi…

Leetcode面试经典150题-55.跳跃游戏

解法都在代码里&#xff0c;不懂就留言或者私信 class Solution {public boolean canJump(int[] nums) {/**如果就一个位置&#xff0c;你本来就在这&#xff0c;肯定可以跳到*/if(nums.length 1) {return true;}/**这个题的解题思路是遍历数组&#xff0c;如果当前位置不在之…

Linux网络——从《计算机网络》到网络编程

文章目录 从《计算机网络》到网络编程从计算机到计算机网络解决问题网络与计算机系统计算机网络的传输流程IP地址与MAC地址 从《计算机网络》到网络编程 科班的同学大多学过计算机网络&#xff0c;而非科班的同学也多多少少听说过一些 计算机网络体系十分繁杂且精妙&#xff…

毕业论文任务书怎么写?超详细指导带你轻松搞定!

AIPaperGPT&#xff0c;论文写作神器~ https://www.aipapergpt.com/ 毕业论文任务书是毕业论文的“指路明灯”&#xff0c;是论文写作的路线规划。很多同学把毕业论文任务书当作形式化的文件草草了事&#xff0c;其实不然。任务书不仅是你整个论文写作的起点&#xff0c;也是确…

艺术体操与骑行的完美协奏:维乐Angel Rise+坐垫,激情与力量的展现!

在艺术体操的赛场上&#xff0c;每一次旋转、每一次跳跃&#xff0c;都凝聚着运动员的力量与技巧。这不仅是一场速度与激情的碰撞&#xff0c;更是一次力量与技巧的交融。正如在骑行的领域里&#xff0c;VELO Angel Rise坐垫以它独特的一体成型设计和技术&#xff0c;为骑行者们…

【论文分享精炼版】 sNPU: Trusted Execution Environments on Integrated NPUs

今天在COMPASS分享了之前写的一个博客&#xff0c;做了进一步的提炼总结&#xff0c;大家可以看看原文~ 今天分享的论文《sNPU: Trusted Execution Environments on Integrated NPUs》来自2024年ISCA&#xff0c;共同一作为Erhu Feng以及Dahu Feng。并且&#xff0c; 这两位作…

《逆水寒手游》在苹果官网亮眼,国产武术游戏激起海外玩家热情

易采游戏网9月10日消息&#xff1a;《逆水寒手游》自上线以来&#xff0c;以其精致的画面、引人入胜的剧情以及创新的玩法&#xff0c;迅速在国内外游戏市场中占据一席之地。如今&#xff0c;这款备受期待的手游更是亮相全球科技巨头苹果公司iPhone16Pro的官网&#xff0c;为全…

lunix磁盘IO await until问题实战排查-实用命令集合

1、Linux查看磁盘读写次数 iostat -x 1 这个命令可以查询磁盘当前平均读写的次数、读写&#xff0c;以及是否await util严重。 2、查看磁盘TPS和读写数据量大小 iostat -d -k 1 10 这个命令可以查看磁盘的tps和读写数据量大小。 -d&#xff1a;显示某块具体硬盘&#x…

已知两圆的圆心半径,求交点坐标——CAD VBA 解决

如下图&#xff0c; dwg图中若干图形&#xff0c;运行代码后提示选择两个圆&#xff0c;然后判断两个圆位置关系和相交点坐标: 本例难点在于通过几何知识求出交点坐标。 几何背景 假设有两个圆&#xff1a; - 圆1&#xff1a;圆心 ( O_1(x_1, y_1) )&#xff0c;半径 ( r_1 ) …

关于支付宝小程序多规格选项的时候点击不起反应的原因分析及修改方法

解决方案&#xff1a; watch的时候&#xff0c;对于对象的赋值&#xff0c;最好用深拷贝&#xff0c;即如下图&#xff1a; watch:{ row: function (nv, ov) {var that this;that.indata.row JSON.parse(JSON.stringify(nv));//如果是对象&#xff0c;请用深入的for (va…

《使用 LangChain 进行大模型应用开发》学习笔记(二)

前言 本文是 Harrison Chase &#xff08;LangChain 创建者&#xff09;和吴恩达&#xff08;Andrew Ng&#xff09;的视频课程《LangChain for LLM Application Development》&#xff08;使用 LangChain 进行大模型应用开发&#xff09;的学习笔记。由于原课程为全英文视频课…

ReLU再进化ReLUMax:自动驾驶的瞬态容错语义分割

ReLU再进化ReLUMax&#xff1a;自动驾驶的瞬态容错语义分割 Abstract 度学习模型在自动驾驶感知中至关重要&#xff0c;但其可靠性面临着算法限制和硬件故障的挑战。我们通过研究语义分割模型的容错性来应对后者。使用已有的硬件故障模型&#xff0c;我们在准确性和不确定性方…

视频号接口列表

目前已有的接口列表&#xff1a; 账号搜索 视频搜索 直播搜索 获取作者信息和作品列表 视频解密并下载 获取视频详情 获取视频评论 获取视频评论的子评论 作品喜欢 作品点赞 作品评论 对作品评论进行评论 关注作者 加入直播间 获取直播间弹幕消息 发送弹幕消息 获取直播间商品…

力扣474-一和零(Java详细题解)

题目链接&#xff1a;474. 一和零 - 力扣&#xff08;LeetCode&#xff09; 前情提要&#xff1a; 因为本人最近都来刷dp类的题目所以该题就默认用dp方法来做。 最近刚学完01背包&#xff0c;所以现在的题解都是以01背包问题为基础再来写的。 如果大家不懂01背包的话&#…