HarmonyOS Next 纯血星河版【三】设计资源 SVG、页面布局元素、组件圆角、背景属性 && 线性布局(主轴、交叉轴)的设置 && 自适应伸缩 && 得物卡片练习 、京东登录页实战练习

LiuJinTao: 2024年4月26日

HarmonyOS Next 纯血星河版【三】

一、设计资源 - svg 图标

在这里插入图片描述
官网地址:https://developer.huawei.com/consumer/cn/design/harmonyos-icon/

1. 代码示例
@Entry
@Component
struct IcDemo {
  build() {
    Column() {
      // 使用 svg 图标,和图片使用的方式一样的
      Image($r('app.media.ic_contacts_5G'))
        .width(100)
        .fillColor(Color.Green)
    }
  }
}
2. 小结

在这里插入图片描述

二、布局元素的组成

在这里插入图片描述

三、 内边距 padding

在这里插入图片描述

四、 外边距 margin

在这里插入图片描述

五、 padding 和 margin 综合练习

需求:实现如下图所示的登录效果
在这里插入图片描述

代码示例;

@Entry
@Component
struct LoginDemo {
  build() {
    Column() {
      Image($r('app.media.touxinag'))
        .width(150)

      Text('全栈攻城狮喜欢音乐')
        .width(200)
        .fontSize(18)
        .fontColor('#FFAACC')
        .margin({
          top: 20,
          right: 45,
          left: 100,
          bottom: 30
        })

        Button('QQ登录')
          .width('80%')
          .margin({
            bottom: 20
          })
        Button('微信登录')
          .width('80%')
          .fontColor(Color.Black)
          .backgroundColor('#ddd')


    }
    .padding(20)
    .width('90%')
  }
}
  • 效果演示
    在这里插入图片描述

六、 边框 border

在这里插入图片描述

七、组件圆角

在这里插入图片描述

  • 特殊圆角
    在这里插入图片描述

八、背景属性

在这里插入图片描述

1. 背景图的基本使用

在这里插入图片描述

  • 属性效果
    在这里插入图片描述

代码示例效果:

在这里插入图片描述

小结:
在这里插入图片描述

2. 背景图位置的设置

在这里插入图片描述

代码示例:
在这里插入图片描述

  • 小结
    在这里插入图片描述
3. 背景位置 - 单位问题

在这里插入图片描述

在这里插入图片描述

  • 不错,建议还是使用 vp 为单位, 反正内部他会帮我们转为px,你想200px,就直接写200vp。
    在这里插入图片描述
4. 背景尺寸

在这里插入图片描述

九、线性布局 - 主轴

在这里插入图片描述

1. 主轴方向排列方式 Column

在这里插入图片描述
在这里插入图片描述

  • 总结
  • 在这里插入图片描述

十、顶部导航 - 练习

在这里插入图片描述
代码示例:

@Entry
@Component
struct CenterTest {
  build() {
    Column() {
      Row() {
        Text('<')
          .fontSize(20)
        Text('个人中心')
          .fontSize(20)
        Image($r('app.media.centertest'))
          .width(30)

      }
      .padding(10)
      .width('100%')
      .justifyContent(FlexAlign.SpaceBetween)
    }
  }
}

在这里插入图片描述

十一、线性布局 - 交叉轴

在这里插入图片描述

  • 小结
    在这里插入图片描述

十二、线性布局练习

在这里插入图片描述

代码示例:
@Entry
@Component
struct HuaWeiListDemo {
  build() {
    Column() {
      Row() {
        Column( { space: 10 }) {
          Text('HUEWEI')
            .fontSize(20)
            .fontWeight(700)
          Text('胡杨不死,麒麟不绝!')
            .fontSize(12)
            .fontColor('#999')
        }
        .alignItems(HorizontalAlign.Start)
        Row() {
          Image($r('app.media.huawei'))
            .width(50)
            .margin({
              right: 20
            })
          Image($r('app.media.ic_contacts_5G'))
            .width(20)
        }
      }
      .backgroundColor('#fff')
      .borderRadius(15)
      .width('100%')
      .justifyContent(FlexAlign.SpaceBetween)
      .padding({
        left: 20,
        right: 20
      })
      .margin({
        top: 20
      })
    }
    .width('100%')
    .height('100%')
    .backgroundColor('#999')
  }
}

在这里插入图片描述

十三、自适应伸缩

  • 份数权重
  • 剩余空间

在这里插入图片描述
代码示例:

@Entry
@Component
struct weightDemo{
  build() {
    Column() {
      Row() {
        Text('状态栏')
          .layoutWeight(1)
          .fontSize(18)
          .margin({ right: 10})
        Image($r('app.media.ic_power_off'))
          .width(50)
          .height(50)
          .margin({ left: 10, right:10})
        Image($r('app.media.ic_wuraomoshi'))
          .width(50)
          .height(50)
          .margin({ left: 10, right:10})
        Image($r('app.media.ic_feixingmoshi'))
          .width(50)
          .height(50)
          .margin({ left: 10, right:10})
      }
      .width(300)
      .height(70)
      .backgroundColor('#fff')
      .borderRadius(15)
    }
    .width('100%')
    .height('100%')
    .backgroundColor('#999')
    .padding({
      top: 100,
      bottom: 50
    })
  }
}

效果展示: 这里除了状态栏占了一份权重,其他的都给了固定的宽度,那么,所有的都属于状态栏的宽度了。

在这里插入图片描述

十四、得物卡片 - 综合练习

在这里插入图片描述

代码示例:
@Entry
@Component
struct DewuDemo {
  build() {
    Column() {
      // 详情区域
      Column() {
        // 图片
        Image($r('app.media.dewu'))
          .width('100%')
          .layoutWeight(1)
          .backgroundImageSize(ImageSize.Cover)
          .borderRadius({
            topLeft: 15,
            topRight: 15
          })
        // 简介区域
        Column( { space: 15 } ) {
          Column({ space: 10 }) {
            Text('Mate 60 | 致敬奔腾不息的你')
              .fontWeight(700)
              .fontSize(20)
            Text('No. 1')
              .fontWeight(700)
              .fontSize(20)
          }
          .width('100%')
          .alignItems(HorizontalAlign.Start)
          // 头像 区域
          Row() {
            Row( { space: 10 }) {
              Image($r('app.media.touxiang_huawei'))
                .width(40)
                .height(40)
                .borderRadius(20)
              Text('HMOS')
                .fontSize(18)
                .fontColor('#999')
            }
            .layoutWeight(1)
            Row({ space: 5 }) {
              Image($r('app.media.ic_dianzan'))
                .width(20)

              Text('9999')
                .fontColor('#999')
            }
            .width(80)
          }
          .width('100%')
          .justifyContent(FlexAlign.SpaceBetween)

        }
        .width('100%')
        .height(130)
        .backgroundColor('#FFF')
        .padding(10)
        .borderRadius( { bottomLeft: 15, bottomRight: 15} )
        }
      .width(300)
      .height(400)


    }
    .width('100%')
    .height('100%')
    .backgroundColor('#fffdf9f9')
    .padding(20)
  }
}
  • 效果演示

在这里插入图片描述

京东登录页 - 实战练习

在这里插入图片描述
代码示例:

@Entry
@Component
struct JDLoginTest {
  build() {
    Column() {
      Column() {
        // 背景图
        // Text()
        //   .backgroundImage($r('app.media.background_loging_image'))
        //   .backgroundImageSize(ImageSize.Cover)
        //   .width('100%')
        //   .height('100%')
        // 整个内容区域

        // 顶部导航栏区域
        Row() {
          Image($r('app.media.ic_public_cancel_filled'))
            .width(16)
            .fillColor('#999')

          Text('帮助')
            .fontSize(16)
            .fontColor('#999')
        }
        .width('100%')
        .height(40)
        .justifyContent(FlexAlign.SpaceBetween)

        // logo区域
        Row() {
          Image($r('app.media.jd_login_image'))
        }
        .width(250)
        .height(250)
        .margin({
          top: 20,
          bottom: 15
        })

        // 输入框区域
        Column( { space: 20}) {
          Row() {
            Text('国家/地址')
              .fontColor('#999')
              .layoutWeight(1)
            Text('中国(+86) >')
              .fontColor('#999')
          }
          .width('100%')
          .height(40)
          .padding({
            left: 17,
            right: 10
          })
          .backgroundColor('#fff')
          .borderRadius(20)
          .justifyContent(FlexAlign.SpaceBetween)
          Row() {
            TextInput({ placeholder: '请输入手机号'})
              .placeholderColor('#999')
              .backgroundColor('#fff')
          }
        }
        // 协议区域
        Row(){
          Checkbox()
            .width(10)

          Text() {
            Span('我已阅读并同意')
            Span('《京东隐私政策》')
              .fontColor('#3274f6')
            Span('《京东用户服务协议》')
              .fontColor('#3274f6')
              .fontColor('#3274f6')
            Span('未注册的手机号自动注册为京东账户')
          }
            .fontSize(12)
            .fontColor('#999')
        }
        .width('100%')
        .margin({
          top: 20,
          bottom: 20
        })
        .alignItems(VerticalAlign.Top)

        // 登录按钮
        Button('登录')
          .backgroundColor('#bf2838')
          .width('100%')
          .margin({
            bottom: 15
          })
        // 注册和忘记密码以及问题反馈区域
        Row() {
          Text('新用户注册')
            .fontSize(14)
            .fontColor('#999')
          Text('账户密码登录')
            .fontSize(14)
            .fontColor('#999')
          Text('无法登陆')
            .fontSize(14)
            .fontColor('#999')
        }
        .width('100%')
        .justifyContent(FlexAlign.SpaceEvenly)
        .margin( { bottom: 50} )

        // 空白的全部由我承担,其他的自己管理好自己。
        Blank()

        // 其他方式登录区域
        Column(){
          Text('其它方式登录')
            .height(22)
            .fontSize(14)
            .fontColor('#999')
            .margin({ bottom: 28})
          Row() {
            Image($r('app.media.huawei'))
              .width(34)
              .height(34)
              .borderRadius(17)
            Image($r('app.media.weixin_login_image'))
              .width(34)
              .height(34)
              .borderRadius(17)
            Image($r('app.media.weibo_login_image'))
              .width(34)
              .height(34)
              .borderRadius(17)
            Image($r('app.media.qq_login_image'))
              .width(34)
              .height(34)
              .borderRadius(17)
          }
          .width('100%')
          .justifyContent(FlexAlign.SpaceEvenly)

        }
        .width('100%')
        .height(100)
      }
      .width('100%')
      .height('100%')
      .padding({
        top: 20,
        right: 20,
        bottom: 50,
        left: 20
      })
      .backgroundImage($r('app.media.background_loging_image'))
      .backgroundImageSize(ImageSize.Cover)
    }
  }
}

效果展示
在这里插入图片描述

总结:
在这里插入图片描述

  • 11
    点赞
  • 14
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

脱发使我稳重

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值