HarmonyOS NEXT仓颉开发语言实战案例:电影App

大家周末好,今天依然为大家分享之前使用ArkTS实现过的案例,一个电影App,今天使用仓颉的UI再次实现,看看仓颉和ArkTs有哪些相同和不同之处。

这个页面的结构比较简单,因为没有导航栏,全都使用List容器实现,最顶部是一个巨大的图片,这个不再演示,继续看下面的部分。

接下来两个部分都有标题了,所以使用ListItemGroup的header来实现,这部分知识点我们最近频繁用到:

复制代码
@Builder func itemHead(text:String) {
    Row{
        Text(text)
        .fontColor(Color.WHITE)
        .fontSize(13)
    }
    .width(100.percent)
    .height(35)
    .alignItems(VerticalAlign.Center)
    .padding(top:3,left:10)
}
ListItemGroup(ListItemGroupParams(header:{=>bind(this.itemHead,this)('分类')})){
}

接下来是分类列表的内容部分,我们首先要定义一个数组,仓颉的数组写法和ArkTS略有不同:

复制代码
@State var types:ArrayList<String> = ArrayList<String>(['全部的','动作','喜剧片','爱情','乡村','都市','战争'])

然后在页面中循环添加分类组件,仓颉的Foreach写法也是和ArkTS不同的:

复制代码
Scroll{
    Row{
        ForEach(types, itemGeneratorFunc: {str:String,index:Int64 =>
            if(index == currentType){
                    Text(str)
                    .fontSize(15)
                    .fontColor(Color.WHITE)
                    .padding(top:8,bottom:8,left:22,right:22)
                    .borderRadius(15)
                    .backgroundColor(0x6152FF)
            }else {
                    Text(str)
                    .fontSize(15)
                    .fontColor(Color.WHITE)
                    .padding(top:8,bottom:8,left:22,right:22)
                    .borderRadius(15)
                    .backgroundColor(Color(6, 4, 31, alpha: 1.0))
            }
                })
    }
}

最底部分电影列表和上面类似,直接贴代码:

复制代码
ListItemGroup(ListItemGroupParams(header:{=>bind(this.itemHead,this)('最受欢迎')})){
    ListItem{
        Scroll{
            Row(10){
                ForEach(ArrayList<String>(['1','1','2']), itemGeneratorFunc: {str:String,index:Int64 =>
                            Image(@r(app.media.fm))
                        .width(124)
                        .height(180)
                        .borderRadius(10)
                        .objectFit(ImageFit.Fill)
                            })
            }
        }
    }
}

以上就是今天的内容分享,感谢阅读。##HarmonyOS语言##仓颉##休闲娱乐#

相关推荐
小雨下雨的雨5 小时前
Flutter 框架跨平台鸿蒙开发 —— SingleChildScrollView 控件之长内容滚动艺术
flutter·ui·华为·harmonyos·鸿蒙
2501_944521006 小时前
rn_for_openharmony商城项目app实战-商品评价实现
javascript·数据库·react native·react.js·ecmascript·harmonyos
lili-felicity6 小时前
React Native for Harmony 企业级 Grid 宫格组件 完整实现
react native·react.js·harmonyos
以太浮标7 小时前
华为eNSP模拟器综合实验之- VLAN聚合(VLAN Aggregation或Super VLAN)解析
运维·网络·华为·信息与通信
lili-felicity8 小时前
React Native 鸿蒙跨平台开发:动态表单全场景实现
react native·harmonyos
奋斗的小青年!!8 小时前
Flutter跨平台开发适配OpenHarmony:文件系统操作深度实践
flutter·harmonyos·鸿蒙
SunkingYang9 小时前
从硬件参数、系统等方面详细对比华为mate80 pro max与iPhone17 pro max
华为·苹果·iphone17·mate80·promax·手机对比
奋斗的小青年!!9 小时前
Flutter跨平台开发OpenHarmony应用:个人中心实现
开发语言·前端·flutter·harmonyos·鸿蒙
人工智能知识库10 小时前
2026年HCCDP-GaussDB工作级开发者题库(详细解析)
数据库·华为·gaussdb·题库·hccdp-gaussdb·工作级开发者认证
IT=>小脑虎11 小时前
鸿蒙开发零基础小白学习知识点【基础版·详细版】
学习·华为·harmonyos