【每日学点HarmonyOS Next知识】tab对齐、相对布局、自定义弹窗全屏、动画集合、回到桌面

ops/2025/3/15 23:24:04/
1、HarmonyOS Tabs 是否能支持 tabbar 居左对齐?

当前方案为自定义tabbar实现,示例demo:

@Entry
@Component
struct TabsExample {@State tabArray: Array<number> = [0, 1,2]@State focusIndex: number = 0@State pre: number = 0@State index: number = 0private controller: TabsController = new TabsController()@State test: boolean = false// 单独的页签@BuilderTab(tabName: string, tabItem: number, tabIndex: number) {Row({ space: 20 }) {Text(tabName).fontSize(18).fontColor(tabItem===this.focusIndex?Color.Red:Color.Black)}.justifyContent(FlexAlign.Center).constraintSize({ minWidth: 35 }).width(80).height(60).borderRadius({ topLeft: 10, topRight: 10 }).onClick(() => {this.controller.changeIndex(tabIndex)this.focusIndex = tabIndex})}build() {Column() {Column() {// 页签Row({ space: 7 }) {Scroll() {Row() {ForEach(this.tabArray, (item: number, index: number) => {this.Tab("页签 " + item, item, index)})}.justifyContent(FlexAlign.Start)}.align(Alignment.Start).scrollable(ScrollDirection.Horizontal).scrollBar(BarState.Off).width('90%')}.alignItems(VerticalAlign.Bottom).width('100%')}.alignItems(HorizontalAlign.Start).width('100%')//tabsTabs({ barPosition: BarPosition.Start, controller: this.controller }) {ForEach(this.tabArray, (item: number, index: number) => {TabContent() {Text('我是页面 ' + item + " 的内容").height(300).width('100%').fontSize(30)}.backgroundColor(Color.Pink)})}.width('100%').barHeight(0).animationDuration(100).onChange((index: number) => {console.log('foo change')this.focusIndex = index})}.height('100%')}
}
2、HarmonyOS RelativeContainer中alignRules的bias属性设置无效?

参考demo:

@Entry
@Component
struct Index {build() {Row() {RelativeContainer() {Row().width(100).height(100).backgroundColor("#FF3333").alignRules({top: {anchor: "__container__", align: VerticalAlign.Top},bottom : {anchor : "__container__", align : VerticalAlign.Bottom},left: {anchor: "__container__", align: HorizontalAlign.Start},right : {anchor : "__container__", align: HorizontalAlign.End},bias : {vertical : 0.3}}).id("row1")}.width(300).height(300).margin({left: 50}).border({width:2, color: "#6699FF"})}.height('100%')}
}
3、HarmonyOS 自定义弹框不能全屏?

参考demo:

@CustomDialog
export struct MyDialog1 {controller1: CustomDialogControllertitle: string = ''build() {Row() {Column({ space: 10 }) {Text(this.title).fontSize(25).fontColor(Color.Blue)Flex({ justifyContent: FlexAlign.SpaceAround }) {Button('取消').onClick(() => {this.controller1.close()}).backgroundColor(0xffffff).fontColor(Color.Black)Button('确认').onClick(() => {this.controller1.close()}).backgroundColor(0xffffff).fontColor(Color.Black)}.width('100%')}.width('100%').backgroundColor(Color.Gray).height('100%')}}
}
// main页面
@Entry
@Component
struct Index {@State dialogData: string = ''@State colorTest: Color = Color.BluedialogController1: CustomDialogController = new CustomDialogController({builder: MyDialog1({title: '弹窗1',}),// 弹窗容器样式是否自定义customStyle: true,offset: { dx: 0, dy: 0 },alignment: DialogAlignment.Top})confirm(data: string) {this.dialogData = dataconsole.info('ssss') // 获取弹窗输入的信息}build() {Row() {Column({ space: 10 }) {Text('这是一个弹窗的测试').fontSize(25).margin(20).fontColor(0x3399FF)Button('点击打开弹窗').onClick(() => {this.dialogController1.open()})}.width('100%')}.height('100%').backgroundColor(Color.White)}
}
4、HarmonyOS 如何实现动画集合?

组件A缩放&旋转动画1S后,再次缩放&旋转,再过4s再次缩放&旋转,再过1s缩放&旋转这4个为一个集合,这个集合一直执行。这种怎么实现。

使用关键帧动画可以实现keyframeAnimateTo参考demo:

import { UIContext } from '@ohos.ArkUI.UIContext';@Entry
@Component
struct Index {@State myScale: number = 1.0;uiContext: UIContext | undefined = undefined;aboutToAppear() {this.uiContext = this.getUIContext?.();}build() {Column() {Circle().width(100).height(100).fill("#46B1E3").margin(100).scale({ x: this.myScale, y: this.myScale })//设置x轴/y轴的缩放.onClick(() => {if (!this.uiContext) {console.info("no uiContext, keyframe failed");return;}this.myScale = 1;// 设置关键帧动画整体播放3次this.uiContext.keyframeAnimateTo({ iterations: 3 }, [{// 第一段关键帧动画时长为800ms,scale属性做从1到1.5的动画duration: 800,event: () => {this.myScale = 1.5;}},{// 第二段关键帧动画时长为500ms,scale属性做从1.5到1的动画duration: 500,event: () => {this.myScale = 1;}}]);})}.width('100%').margin({ top: 5 })}
}
5、HarmonyOS 回到桌面API咨询?

APP中有功能会引导用户回到桌面添加服务卡片,是否有API可以触发回到桌面。

窗口里有minimize方法,这个接口会通知ams窗口退后台,来实现app回到后台的效果 参考链接:https://developer.huawei.com/consumer/cn/doc/harmonyos-references-V5/js-apis-window-V5#minimize11
minimize(callback: AsyncCallback<void>): void
此接口根据调用对象不同,实现不同的功能:

  • 当调用对象为主窗口时,实现最小化功能,可在Dock栏中还原。

  • 当调用对象为子窗口时,实现隐藏功能,不可在Dock栏中还原,可以使用showWindow()进行还原。悬浮窗类型的窗口对象,调用此接口会报1300002错误码。


http://www.ppmy.cn/ops/166064.html

相关文章

Manus全球首个通用Agent,Manus AI:Agent应用的ChatGPT时刻

文章目录 前言Manus AI: 全球首个通用AgentManus AI: 技术架构与创始人经历AI Agent的实现框架与启示AI Agent的发展预测行业风险提示 前言 这是一篇关于Manus AI及其在通用人工智能领域的应用和前景的报告&#xff0c;主要介绍了Manus AI的产品定位、功能、技术架构、创始人经…

数据分析项目:基于LSTM的微博评论情感分析

一、引言 随着社交媒体的蓬勃发展&#xff0c;微博等平台积累了海量的用户生成内容&#xff0c;其中蕴含着丰富的用户情感信息。对这些情感信息进行分析&#xff0c;能够帮助我们更好地理解公众舆论、品牌口碑以及用户需求等。本项目旨在构建一个基于长短期记忆网络&#xff0…

【机器学习chp12】半监督学习(自我训练+协同训练多视角学习+生成模型+半监督SVM+基于图的半监督算法+半监督聚类)

目录 一、半监督学习简介 1、半监督学习的定义和基本思想 2、归纳学习 和 直推学习 &#xff08;1&#xff09;归纳学习 &#xff08;2&#xff09;直推学习 3、半监督学习的作用与优势 4、半监督学习的关键假设 5、半监督学习的应用 6、半监督学习的常见方法 7、半…

深入理解Linux网络随笔(七):容器网络虚拟化--Veth设备对

深入理解Linux网络随笔&#xff08;七&#xff09;&#xff1a;容器网络虚拟化 微服务架构中服务被拆分成多个独立的容器&#xff0c;docker网络虚拟化的核心技术为&#xff1a;Veth设备对、Network Namespace、Bridg。 Veth设备对 veth设备是一种 成对 出现的虚拟网络接口&…

QuickAPI 和 DBAPI 谁更香?SQL生成API工具的硬核对比(一)

最近低代码开发火得不行&#xff0c;尤其是能把数据库秒变API的工具&#xff0c;简直是开发者的救星。今天咱就聊聊两款国内玩家&#xff1a;QuickAPI&#xff08;麦聪软件搞出来的低代码神器&#xff09;和 DBAPI&#xff08;开源社区的硬核作品&#xff09;。这两货都能靠SQL…

每天五分钟深度学习PyTorch:为什么需要循环神经网络RNN?

本文重点 前面我们学习了卷积神经网络CNN,以及如何使用pytorch搭建卷积神经网络CNN,本文我们学习如何使用循环神经网络RNN 文本分类的方法 比如我们现在需要搭建模型完成一个分类任务,现在有一个文本为: I hate this boring movie 我们可以搭建下面的模型完成分类任务: 对…

学习 springboot -Bean 管理(注册条件)

前言 上一篇 博客 :学习springboot-Bean管理&#xff08;Bean 注册&#xff0c;Bean 扫描&#xff09;-CSDN博客我们了解了 bean 注册需要使用到 Bean 和Import 将第三方jar 包的对象 注入到ioc 容器 如下图所示 通过图片&#xff0c;可以看到Country 对象和Province 对象已…

字符串函数和结构题内存对齐

图下为函数使用&#xff1a; #include <ctype.h>int main() {int ret isdigit(Q);printf("%d\n", ret);return 0; }int main() {printf("%c\n", toupper(a));printf("%c\n", tolower(A));return 0; }