当前位置: 首页 > news >正文

鸿蒙界面开发

界面开发

image-20240722162900142

image-20240722162934196

//构建 → 界面
build() {//行Row(){//列Column(){//文本 函数名(参数)  对象.方法名(参数) 枚举名.变量名Text(this.message).fontSize(40)//设置文本大小.fontWeight(FontWeight.Bold)//设置文本粗细.fontColor('#ff2152')//设置文本颜色}.width('100%')}.height('100%')
}

界面开发-布局思路

image-20240722164826813

image-20240722165124543

//构建 → 界面
build() {//布局思路:先布局在排版Column(){//内容Text('小说简介')Row(){Text('都市')Text('生活')Text('情感')Text('男频')}}//最外面只能有一层容器组件,需要编写要在容器内编写
}

image-20240722165753143

属性方法

image-20240723153251329

//构建 → 界面
build() {//布局思路:先布局在排版Column(){//内容Text('小说简介').width('100%').fontSize(25).fontWeight(FontWeight.Bolder).height(50)Row(){Text('都市').fontColor(Color.Blue).backgroundColor(Color.Brown).width(50).height(40)Text('生活').fontColor(Color.Brown).backgroundColor(Color.Green).width(50).height(40)Text('情感').backgroundColor(Color.Pink).width(50).height(40)Text('男频').backgroundColor(Color.Orange).width(50).height(40)}.width('100%')}//最外面只能有一层容器组件,需要编写要在容器内编写
}

image-20240722171119332

字体颜色

image-20240722171237012

//2、综合练习:今日头条置顶新闻
Column(){Text('学鸿蒙,就来陈哈哈~').fontSize(15).width('100%').fontWeight(FontWeight.Bold).height(25)Row(){Text('置顶').fontColor(Color.Red).fontSize(10).width(30)Text('新华社').fontSize(10).fontColor('#888').width(40)Text('4680评论').fontSize(10).fontColor('#888').width(50)}.width('100%')
}.width('100%')

image-20240722203930759

文字溢出省略号、行高

image-20240722204950609

Column(){Text('HarmonyOS开发初体验').width('100%').fontWeight(FontWeight.Bold).lineHeight(50).fontSize(24)Text('方舟开发框架(简称ArkUI)为HarmonyOS应用的UI开发提供了完整的基础设施,包括简洁的UI语法、丰富的UI功能(组件、布局、动画以及交互事件),以及实时界面预览工具等,可以支持开发者进行可视化界面开发。').width('100%').lineHeight(24).fontColor('#888')//重点记忆溢出省略号.textOverflow({overflow:TextOverflow.Ellipsis}).maxLines(2)//配合使用能见度两行
}

image-20240722210020372

Image图片组件

image-20240722210202025

//构建 → 界面
build() {//1、网络图片加载 image('网图地址')// Column(){//   Image('https://www.itheima.com/images/logo.png')//     .width(200)// }//2、本地图片加载 image($r('app.media.文件名'))Column(){Image($r('app.media.startIcon')).width(200)Text('耐克龙年限定款!!!').fontSize(20).width(200)Row(){Image($r('app.media.startIcon')).width(20)Text('  令人脱发的代码')}.width(200)}

image-20240722212557000

输入框与按钮

image-20240722215112090

build() {//控制组件间的距离,可以给Column设置{space:间隙大小}Column({space:10}){TextInput({placeholder:'请输入用户名'}).type(InputType.Normal)TextInput({placeholder:'请输入密码'}).type(InputType.Password)Button('登录').backgroundColor('#3575ED').width(200)}
}

image-20240722215230041

综合实训

image-20240722220536058

build() {//构建界面核心思路://1.排版(思考布局)//2,内容(基础组件)//3.美化(属性方法)Column({space:10}){Image($r('app.media.startIcon')).width(50)TextInput({placeholder:'输入用户名'})TextInput({placeholder:'请输入密码'}).type(InputType.Password)Button('登录').width('100%')Row({space:15}){Text('前往注册')Text('忘记密码')}}.width('100%').padding(20)
}

设计资源-svg图标

image-20240723142343723

鸿蒙图标库:

https://developer.huawei.com/consumer/cn/design/harmonyos-icon/

image-20240723153857558

布局元素的组成

image-20240723154038749

内边距padding

image-20240723154146773

外边距margin

image-20240723154438249

练习:

image-20240723155841146

//构建 → 界面
build() {Column(){Image($r('app.media.startIcon')).width(50).margin({top:120})Text('大王叫我来巡山').fontSize(25).fontWeight(FontWeight.Bold).margin({top:20,})Button('QQ音乐登录').fontColor(Color.White).fontWeight(FontWeight.Bold).backgroundColor('#387DF6').width('100%').margin({top:80})Button('微信登录').fontColor(Color.Black).fontWeight(FontWeight.Bold).backgroundColor('#DFDFDF').width('100%').margin({top:15})}.width('100%').padding(20)}
边框

image-20240723155920791

//构建 → 界面
build() {Column(){Text('四条边').fontColor(Color.Red).padding(5).border({width:1,//宽度color:Color.Red,//颜色style:BorderStyle.Dotted//央视(实线 虚线 点线)}).margin({bottom:20})Text('单边框').fontColor(Color.Red).padding(5)//单边框,可以通过left right top bottom配置四个方向边框.border({width:{left:1,right:3},color:{left:Color.Yellow,right:'#ff68'},style:{left:BorderStyle.Solid,right:BorderStyle.Dotted}})}.width('100%').padding(20)
}

image-20240723161304264

设置组件圆角

image-20240723161432314

image-20240723161643150

特殊形状圆角设置

image-20240723161744665

//构建 → 界面
build() {Column(){Text('四条边').fontColor(Color.Red).padding(5).border({width:1,//宽度color:Color.Red,//颜色style:BorderStyle.Dotted//央视(实线 虚线 点线)}).margin({bottom:20})Text('单边框').fontColor(Color.Red).padding(5)//单边框,可以通过left right top bottom配置四个方向边框.border({width:{left:1,right:3},color:{left:Color.Yellow,right:'#ff68'},style:{left:BorderStyle.Solid,right:BorderStyle.Dotted}})//倒角Text('倒角').backgroundColor(Color.Pink).margin(30).padding(10).borderRadius({topLeft:10,bottomRight:10})//图片Image($r('app.media.startIcon')).width(100).height(100).borderRadius(50)//正圆Text('正圆').backgroundColor(Color.Pink).margin(30).padding(10).width(50)//宽高一样.height(50).borderRadius(25)//圆角是宽或者高的一半//胶囊Text('胶囊').backgroundColor(Color.Green).padding(20).width(150)//宽比高大.height(50).borderRadius(25)//圆角是高的一半}.width('100%').padding(20)
}

背景图-banckgroundImage

image-20240723162829447

image-20240723163015831

Text('tupian').padding(20).backgroundColor(Color.Orange).margin(20).width(400).height(400).backgroundImage($r('app.media.app_icon'),ImageRepeat.XY)//图片重复,x横轴,y纵轴,xy铺满

image-20240723192912180

背景属性

image-20240723194105894

//构建 → 界面
build() {//backgroundImagePosition//1,传入对象,设置位置坐标,背景图片的左顶点//{x:坐标值,Y:坐标值}//注意:坐标值的单位,和宽高的默认单位不同的,显示出来大小会不同//2,Alignment枚举,设置一些特殊的位置(中央、左顶点..)//Center TopStart左J顶点TopEnd右顶点BottomEnd右下...Column(){Text().width(300).height(200).backgroundColor(Color.Pink).backgroundImage($r('app.media.startIcon')).backgroundImagePosition({x:100,y:100}).backgroundImagePosition(Alignment.Center)}.width('100%').padding(20)
}

image-20240723200908429

单位问题

image-20240723202122323

背景属性image-20240723202152219

image-20240723202333202

Text().height(200).width(300).backgroundImage($r('app.media.huawei')).backgroundImageSize(ImageSize.Cover)

image-20240723204058158

线性布局

image-20240723204130454

image-20240723204256594

//纵向布局
.build() {Column(){Text().width(200).height(100).backgroundColor(Color.Pink).borderWidth(1)Text().width(200).height(100).backgroundColor(Color.Pink).borderWidth(1)Text().width(200).height(100).backgroundColor(Color.Pink).borderWidth(1)}.width('100%').height('100%')//设置排布主方向的对齐方式(主轴)//1.Start(排布主方向)主轴起始位置对齐//2.Center主轴居中对齐//3.End主轴结束位置对齐//4.SpaceBetween贴边显示,中间的元素均匀分布间隙//5.Space正ound间隙环绕0.5 1 1 1 0.5的间隙分布,靠边只有一半的间隙//6,SpaceEvenly间隙均匀环绕,靠边也是完整的一份间隙//justifyContent(枚举FlexAlign)ctrL+p cmd+p//.justifyContent(FLexAlign.Center)//.justifyContent(FLexAlign.SpaceBetween)//justifyContent(FLexAlign.SpaceAround).justifyContent(FlexAlign.Center)
//横向布局
build() {Row(){Text().width(50).height(200).backgroundColor(Color.Pink).borderWidth(1)Text().width(50).height(200).backgroundColor(Color.Pink).borderWidth(1)Text().width(50).height(200).backgroundColor(Color.Pink).borderWidth(1)}.width('100%').height('100%')//设置排布主方向的对齐方式(主轴)//1.Start(排布主方向)主轴起始位置对齐//2.Center主轴居中对齐//3.End主轴结束位置对齐//4.SpaceBetween贴边显示,中间的元素均匀分布间隙//5.Space正ound间隙环绕0.5 1 1 1 0.5的间隙分布,靠边只有一半的间隙//6,SpaceEvenly间隙均匀环绕,靠边也是完整的一份间隙//justifyContent(枚举FlexAlign)ctrL+p cmd+p//.justifyContent(FLexAlign.Center)//.justifyContent(FLexAlign.SpaceBetween)//justifyContent(FLexAlign.SpaceAround).justifyContent(FlexAlign.SpaceEvenly)}

image-20240723210216442

个人中心-顶部导航栏

image-20240723210319328

//构建 → 界面
build() {Column(){Row(){Image($r('app.media.ic_public_arrow_left_filled')).width(30)Text('个人中心').fontSize(24)Image($r('app.media.ic_gallery_photoedit_more')).width(30)}.width('100%').height(40).justifyContent(FlexAlign.SpaceBetween).padding({left:10,right:10}).backgroundColor(Color.White)}.width('100%').height('100%').backgroundColor(Color.Pink )

image-20240723211849585

image-20240723211937208

//Row的交叉轴的对齐方式(垂直向下的交叉轴)
Row(){内容……}.alignItems(VerticalAlign.Top)//Column的交叉轴的对齐方式(垂直向右的交叉轴)
Column(){内容……}.alignItems(VerticalAlign.Top)

image-20240723212615089

得物-列表项

image-20240723223639851

//构建 → 界面
build() {Column(){//左侧列Row(){Column({space:10}){Text('玩一玩').fontWeight(FontWeight.Bold).fontSize(18)Row(){Text('签到兑礼').fontColor('#ccc').fontSize(12)Text('|超多大奖').fontColor('#ccc').fontSize(12)Text('  超好玩').fontColor('#ccc').fontSize(12)}}.alignItems(HorizontalAlign.Start)//右侧行Row(){Image($r('app.media.startIcon')).width(50).margin({right:10})Image($r('app.media.ic_public_arrow_right_filled')).width(30).fillColor('#ccc')}.justifyContent(FlexAlign.SpaceBetween)}.justifyContent(FlexAlign.SpaceBetween).backgroundColor(Color.White).width('100%').height(80).borderRadius(10).padding({left:15,right:15})}.width('100%').height('100%').padding(10).backgroundColor(Color.Pink)}

image-20240723223724362

相关文章:

  • 北京网站建设多少钱?
  • 辽宁网页制作哪家好_网站建设
  • 高端品牌网站建设_汉中网站制作
  • Redis 主从搭建
  • 过滤出List集合的元素是Person对象,过滤出每个元素非null的name字段得到String类型的集合
  • vue侦听器(Watch)精彩案例剖析一
  • Redission中的Lua脚本写法、理解
  • Python面试题:Python中的单例模式及其实现
  • 基于单片机控制的锂电池充电和保护系统研究
  • 项目实战二
  • 利用Java调用人脸身份证比对接口
  • Prometheus监控Elasticsearch
  • 聚观早报 | Meta将推出新款AR眼镜;iPhone SE 4将升级显示屏
  • shell脚本教程学习
  • Qt:26.Qt项目:贪吃蛇游戏
  • redis全局唯一ID生成策略、countDownLatch、Lambda表达式总结
  • 《峡谷小狐仙-多模态角色扮演游戏助手》复现流程
  • Java IO模型深入解析:BIO、NIO与AIO
  • JavaScript 如何正确处理 Unicode 编码问题!
  • Apache Pulsar 2.1 重磅发布
  • Netty+SpringBoot+FastDFS+Html5实现聊天App(六)
  • node和express搭建代理服务器(源码)
  • Sequelize 中文文档 v4 - Getting started - 入门
  • Vue2 SSR 的优化之旅
  • 订阅Forge Viewer所有的事件
  • 浏览器缓存机制分析
  • 名企6年Java程序员的工作总结,写给在迷茫中的你!
  • 手机app有了短信验证码还有没必要有图片验证码?
  • 学习HTTP相关知识笔记
  • 一天一个设计模式之JS实现——适配器模式
  • LevelDB 入门 —— 全面了解 LevelDB 的功能特性
  • ​数据链路层——流量控制可靠传输机制 ​
  • #宝哥教你#查看jquery绑定的事件函数
  • (NO.00004)iOS实现打砖块游戏(九):游戏中小球与反弹棒的碰撞
  • (多级缓存)多级缓存
  • (分享)自己整理的一些简单awk实用语句
  • (机器学习的矩阵)(向量、矩阵与多元线性回归)
  • (亲测成功)在centos7.5上安装kvm,通过VNC远程连接并创建多台ubuntu虚拟机(ubuntu server版本)...
  • (四) 虚拟摄像头vivi体验
  • (四)模仿学习-完成后台管理页面查询
  • (推荐)叮当——中文语音对话机器人
  • (转)EXC_BREAKPOINT僵尸错误
  • .NET / MSBuild 扩展编译时什么时候用 BeforeTargets / AfterTargets 什么时候用 DependsOnTargets?
  • .Net MVC + EF搭建学生管理系统
  • .net refrector
  • .NET Remoting学习笔记(三)信道
  • .NET/C# 如何获取当前进程的 CPU 和内存占用?如何获取全局 CPU 和内存占用?
  • .net中生成excel后调整宽度
  • @vue-office/excel 解决移动端预览excel文件触发软键盘
  • [20160807][系统设计的三次迭代]
  • [AutoSar]BSW_Com07 CAN报文接收流程的函数调用
  • [Bug]使用gradio创建应用提示AttributeError: module ‘gradio‘ has no attribute ‘inputs‘
  • [BZOJ 4034][HAOI2015]T2 [树链剖分]
  • [BZOJ2850]巧克力王国
  • [C/C++] C/C++中数字与字符串之间的转换
  • [caffe(二)]Python加载训练caffe模型并进行测试1
  • [CocosCreator]Android的增加AndroidX的动态权限
  • [EFI]英特尔 冥王峡谷 NUC8i7HVK 电脑 Hackintosh 黑苹果efi引导文件