【鸿蒙实战开发】鸿蒙next版开发基础布局

今日核心:

1.设计资源-图标库

2.属性:布局属性、背景属性

3.线性布局

1. 设计资源-图标库

HarmonyOS 图标库为 HarmonyOS 开发者提供丰富的在线图标资源,涵盖多种使用场景以及风格分类,提供灵活的颜色、大小和格式定义,满足不同角色的下载需求
在这里插入图片描述

使用步骤:设计师提供图标/下载图标 → 使用图标

1.1. 下载图标

●HarmonyOS 图标库
●IconFont 图标库

进入图标库网站,下载 SVG 格式,存储到工程目录:resources/base/media/
在这里插入图片描述

HarmonyOS 图标默认命名以 ic_ 开头,其他图标库下载的图标素材建议修改为与 HarmonyOS 命名规则相同。

1.2. 使用图标

使用 Image 组件显示图标,添加 fillColor() 属性修改图标颜色

@Entry
@Component
struct Index {
build() {
Column() {
  Image($r('app.media.ic_gallery_create'))
    .width(30)
    .aspectRatio(1)
    .fillColor('#f60')}
    .padding(20)
  }
}

2. 布局属性

组件布局
在这里插入图片描述
在这里插入图片描述

2.1. 内边距 padding

作用:在组件内添加间距,拉开内容与组件边缘之间的距离
属性:数字 或 对象{}

●数字:上下左右内边距相同
●对象{}:配合 left、right、top、bottom 单独设置某个方向内边距

@Entry 
@Component 
struct Index { 
  build() { 
    Column() { 
      Row() { 
        Text('文字1') 
          .backgroundColor(Color.Pink) 
          .margin(20) 
        Text('文字2') 
          .backgroundColor(Color.Orange) 
          .margin({ top: 10, right: 20, bottom: 40, left: 80 }) 
        } 
      } 
    } 
  }

2.2. 外边距 margin

作用:在组件外面添加间距,拉开两个组件之间的距离
属性:margin
属性:数字 或 对象{}

●数字:上下左右内边距相同
●对象{}:配合 left、right、top、bottom 单独设置某个方向内边距

@Entry 
@Component 
struct Index { 
  build() { 
    Column() { 
      Row() { 
        Text('文字1') 
          .backgroundColor(Color.Pink) 
          .margin(20) Text('文字2') 
          .backgroundColor(Color.Orange) 
          .margin({ top: 10, right: 20, bottom: 40, left: 80 
        }) 
      } 
    } 
  } 
}

2.3. 案例-QQ音乐登录

在这里插入图片描述

@Entry 
@Component 
struct Index { 
  build() { 
    Column() { 
      Image($r('app.media.ic_user')) 
        .width(100) 
        .margin({ bottom: 10 }) 
      Text('大王叫我来巡山') 
        .fontWeight(700) 
        .margin({ bottom: 40}) 
      Button('QQ登录') 
        .width('100%') 
        .backgroundColor('#367bf6') 
      Button('微信登录') 
        .width('100%') 
        .fontColor('#000') 
        .backgroundColor('#ddd') 
        .margin({ top: 10 }) 
      } 
      .padding(20) 
    } 
  }

2.4. 边框属性

2.4.1. 四个方向边框相同

属性:border()
参数:{width?: 数字, color?: ‘’, style?: BorderStyle},
● width:边框宽度,边框宽度默认值为0,即不显示边框
● color:边框颜色
● style:边框样式,BorderStyle为枚举类型

Solid:实线(默认)
Dashed&#
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值