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

做的网站图片显示一半今日新闻头条新闻今天

做的网站图片显示一半,今日新闻头条新闻今天,怎样做推广网站,献县做网站的本文从目前流行的垂类市场中,选择即时通讯应用作为典型案例详细介绍HarmonyOS NEXT的各类布局在实际开发中的综合应用。即时通讯应用的核心功能为用户交互,主要包含对话聊天、通讯录,社交圈等交互功能。 应用首页 创建一个包含一列的栅格布…

本文从目前流行的垂类市场中,选择即时通讯应用作为典型案例详细介绍HarmonyOS NEXT的各类布局在实际开发中的综合应用。即时通讯应用的核心功能为用户交互,主要包含对话聊天、通讯录,社交圈等交互功能。

应用首页

创建一个包含一列的栅格布局,显示文本“首页”,并且监听断点变化,当断点发生变化时更新 currentBreakpoint状态。

  • 示例代码
    @Entry
    @Component
    struct Index {@StorageLink('currentBreakpoint') currentBreakpoint: string = 'sm';build() {GridRow({ columns: 1 }) {GridCol({ span: 1 } ) {Column() {Text('首页')}.width('100%').height('100%')}}.onBreakpointChange((breakPoint => {this.currentBreakpoint = breakPoint;}))}
    }
    
    在这里插入图片描述

装饰器

  • @Entry:标记这是一个页面入口
  • @Component:标记这是一个组件

状态管理

  • @StorageLink:全局UI状态存储。
  • currentBreakpoint:声明并初始化了一个字符串类型的状态变量,初始值为 ‘sm’,这可能表示屏幕宽度的断点。

布局和结构

  • GridRowGridCol:表示一个栅格布局,GridRow 包含一行,GridCol 表示该行中的一列。
  • columns: 1span: 1:指定网格布局中的列数和列的跨度。

断点变化处理

  • .onBreakpointChange:绑定一个事件处理函数,当断点变化时触发。
  • (breakPoint => { this.currentBreakpoint = breakPoint; }):定义了一个箭头函数,将新的断点值赋给 currentBreakpoint

HomeTab组件

BottomNavigation构造器

BottomNavigation构建器函数用于创建一个带有图像和文本的底部导航按钮,具有自适应布局和状态变化的功能。通过点击按钮,可以更新当前页面索引,从而改变按钮的显示状态(例如图像和文本的颜色)。

  • 示例代码
interface BottomNavigationProps {index: number;img: Resource;selectImg?: Resource;title: Resource | string;
}@BuilderBottomNavigation(button: BottomNavigationProps) {Column() {Image(this.currentPageIndex === button.index ? button.selectImg : button.img).objectFit(ImageFit.Contain).width(this.currentBreakpoint === 'lg' ? '24vp' : '22vp').height(this.currentBreakpoint === 'lg' ? '24vp' : '22vp')Text(button.title).fontColor(this.currentPageIndex === button.index ? '#0A59F7' : Color.Black).opacity(this.currentPageIndex === button.index ? 1 : 0.6).fontWeight(500).textAlign(TextAlign.Center).fontSize('10fp').lineHeight('14vp').fontFamily('HarmonyHeiTi-Bold').margin({ top: '4vp' })}.alignItems(HorizontalAlign.Center).justifyContent(FlexAlign.Center).onClick(() => {this.currentPageIndex = button.index;})}
}

参数类型约束

interface BottomNavigationProps {index: number;img: Resource;selectImg?: Resource;title: Resource | string;
}
  • index:按钮的索引,用于标识按钮。
  • img:按钮的默认图像资源。
  • selectImg:按钮的选中状态图像资源(可选)。
  • title:按钮的标题,可以是资源或字符串。

构造器函数

@Builder
BottomNavigation(button: BottomNavigationProps) {
  • @Builder:表示这是一个构建器函数,用于构建UI组件。
  • BottomNavigation(button: BottomNavigationProps):定义了接收一个 BottomNavigationProps 类型的参数 button。

组件布局

Column() {Image(this.currentPageIndex === button.index ? button.selectImg : button.img).objectFit(ImageFit.Contain).width(this.currentBreakpoint === 'lg' ? '24vp' : '22vp').height(this.currentBreakpoint === 'lg' ? '24vp' : '22vp')
  • Column():创建一个列布局,用于垂直排列组件。
  • Image(...):根据当前页面索引和按钮索引是否匹配来选择显示按钮的图像或选中状态的图像。
  • objectFit(ImageFit.Contain):设置图像的适应方式为“Contain”。
  • .width(...) 和 .height(...):根据断点调整图像的宽度和高度。

文本设置

Text(button.title).fontColor(this.currentPageIndex === button.index ? '#0A59F7' : Color.Black).opacity(this.currentPageIndex === button.index ? 1 : 0.6).fontWeight(500).textAlign(TextAlign.Center).fontSize('10fp').lineHeight('14vp').fontFamily('HarmonyHeiTi-Bold').margin({ top: '4vp' })
  • Text(button.title):显示按钮的标题。
  • .fontColor(...):根据按钮是否被选中设置字体颜色。
  • .opacity(...):根据按钮是否被选中设置透明度。
  • .fontWeight(500):设置字体粗细。
  • .textAlign(TextAlign.Center):设置文本对齐方式为居中。
  • .fontSize('10fp') 和 .lineHeight('14vp'):设置字体大小和行高。
  • .fontFamily('HarmonyHeiTi-Bold'):设置字体样式。
  • margin({ top: '4vp' }):设置顶部外边距。

列对齐和点击事件

.alignItems(HorizontalAlign.Center)
.justifyContent(FlexAlign.Center)
.onClick(() => {this.currentPageIndex = button.index;
})
  • .alignItems(HorizontalAlign.Center):设置列交叉轴居中对齐。
  • .justifyContent(FlexAlign.Center):设置列主轴居中对齐。
  • .onClick(...):绑定点击事件处理函数,当按钮被点击时更新 currentPageIndex 为按钮的索引。

HomeTab布局

构建了一个包含底部导航栏的界面布局。使用TabsTabContent组件来构建一个带有多个标签页的布局,每个标签页都通过BottomNavigation函数生成按钮,这些按钮包含图像和文本,并且具有自适应布局和状态变化的功能。通过点击标签页按钮,可以更新currentPageIndex,从而改变当前显示的页面内容。

  • 示例代码
interface BottomNavigationProps {index: number;img: Resource;selectImg?: Resource;title: Resource | string;
}@Component
export default struct HomeTab {@StorageProp('currentBreakpoint') currentBreakpoint: string = 'sm';@Link currentPageIndex: number;build() {Column() {Tabs({ barPosition: this.currentBreakpoint === 'lg' ? BarPosition.Start : BarPosition.End }) {TabContent().tabBar(this.BottomNavigation({index: 0,img: $r('app.media.icon_message'),selectImg: $r('app.media.icon_message_selected'),title: '消息'}))TabContent().tabBar(this.BottomNavigation({index: 1,img: $r('app.media.icon_contacts'),selectImg: $r('app.media.icon_contacts_selected'),title: '通讯录'}))TabContent().tabBar(this.BottomNavigation({index: 2,img: $r("app.media.icon_social_circle"),selectImg: $r("app.media.icon_social_circle_selected"),title: '朋友圈'}))TabContent().tabBar(this.BottomNavigation({index: 3,img: $r('app.media.icon_me'),selectImg: $r('app.media.icon_me'),title: '我的'}))}.vertical(this.currentBreakpoint === 'lg').height('100%').margin({top: this.currentBreakpoint === 'lg' ? '' : '6.5vp',bottom: this.currentBreakpoint === 'lg' ? '' : '7.5vp'})}.backgroundColor('#F1F3F5').expandSafeArea([], [SafeAreaEdge.BOTTOM])}@BuilderBottomNavigation(button: BottomNavigationProps) {Column() {Image(this.currentPageIndex === button.index ? button.selectImg : button.img).objectFit(ImageFit.Contain).width(this.currentBreakpoint === 'lg' ? '24vp' : '22vp').height(this.currentBreakpoint === 'lg' ? '24vp' : '22vp')Text(button.title).fontColor(this.currentPageIndex === button.index ? '#0A59F7' : Color.Black).opacity(this.currentPageIndex === button.index ? 1 : 0.6).fontWeight(500).textAlign(TextAlign.Center).fontSize('10fp').lineHeight('14vp').fontFamily('HarmonyHeiTi-Bold').margin({ top: '4vp' })}.alignItems(HorizontalAlign.Center).justifyContent(FlexAlign.Center).onClick(() => {this.currentPageIndex = button.index;})}
}

Link状态存储

@Link currentPageIndex: number;
  • @Link:标记currentPageIndex为一个Link状态变量,子组件中被@Link装饰的变量与其父组件中对应的数据源建立双向数据绑定。
  • currentPageIndex:当前页面的索引。

标签页

Tabs({ barPosition: this.currentBreakpoint === 'lg' ? BarPosition.Start : BarPosition.End }) {
  • Tabs:创建一个标签页组件。
  • barPosition:根据当前断点设置标签栏的位置,如果断点为 lg,则标签栏位置为Start,否则为End

安全区域

.backgroundColor('#F1F3F5')
.expandSafeArea([], [SafeAreaEdge.BOTTOM])
  • .expandSafeArea([], [SafeAreaEdge.BOTTOM]):扩展安全区域到底部,确保内容不会被系统导航栏遮挡。

实现效果图

在这里插入图片描述

参考文章

  • 栅格布局
  • 线性布局
  • 全局状态存储
  • Tabs

文章转载自:
http://habitancy.rmyn.cn
http://scalenus.rmyn.cn
http://columbic.rmyn.cn
http://skoal.rmyn.cn
http://cancerophobia.rmyn.cn
http://calcrete.rmyn.cn
http://crapoid.rmyn.cn
http://crispate.rmyn.cn
http://flamdoodle.rmyn.cn
http://phillumenist.rmyn.cn
http://sporeling.rmyn.cn
http://chorography.rmyn.cn
http://relic.rmyn.cn
http://realistically.rmyn.cn
http://architectonics.rmyn.cn
http://subcaudal.rmyn.cn
http://hearthrug.rmyn.cn
http://oxaloacetate.rmyn.cn
http://intermixture.rmyn.cn
http://hitchcockian.rmyn.cn
http://pragmatics.rmyn.cn
http://approve.rmyn.cn
http://jonesian.rmyn.cn
http://derry.rmyn.cn
http://auxochrome.rmyn.cn
http://madrid.rmyn.cn
http://scutcheon.rmyn.cn
http://piscivorous.rmyn.cn
http://decomposer.rmyn.cn
http://mishap.rmyn.cn
http://hodograph.rmyn.cn
http://fluidics.rmyn.cn
http://servantgirl.rmyn.cn
http://rebop.rmyn.cn
http://barbarianize.rmyn.cn
http://technochemistry.rmyn.cn
http://posseman.rmyn.cn
http://beauideal.rmyn.cn
http://bandung.rmyn.cn
http://piptonychia.rmyn.cn
http://persorption.rmyn.cn
http://iowa.rmyn.cn
http://announceable.rmyn.cn
http://subfusc.rmyn.cn
http://hasidism.rmyn.cn
http://tergiversation.rmyn.cn
http://volleyfire.rmyn.cn
http://frightening.rmyn.cn
http://draughty.rmyn.cn
http://tumblerful.rmyn.cn
http://stratigraphic.rmyn.cn
http://kulak.rmyn.cn
http://currency.rmyn.cn
http://gelable.rmyn.cn
http://radioscopically.rmyn.cn
http://condemnable.rmyn.cn
http://vicariously.rmyn.cn
http://outrace.rmyn.cn
http://smallboy.rmyn.cn
http://lognormal.rmyn.cn
http://palatinate.rmyn.cn
http://report.rmyn.cn
http://cybernatic.rmyn.cn
http://spinet.rmyn.cn
http://micron.rmyn.cn
http://wassailer.rmyn.cn
http://lubber.rmyn.cn
http://fanfold.rmyn.cn
http://pianola.rmyn.cn
http://reykjavik.rmyn.cn
http://inculpation.rmyn.cn
http://sympathism.rmyn.cn
http://copydesk.rmyn.cn
http://swain.rmyn.cn
http://laniate.rmyn.cn
http://neolite.rmyn.cn
http://waec.rmyn.cn
http://futuristic.rmyn.cn
http://galeiform.rmyn.cn
http://rockwork.rmyn.cn
http://tidy.rmyn.cn
http://filch.rmyn.cn
http://invaluably.rmyn.cn
http://dol.rmyn.cn
http://batsman.rmyn.cn
http://napa.rmyn.cn
http://organometallic.rmyn.cn
http://mesembryanthemum.rmyn.cn
http://ebonize.rmyn.cn
http://likely.rmyn.cn
http://context.rmyn.cn
http://ataxy.rmyn.cn
http://bechuana.rmyn.cn
http://omophagia.rmyn.cn
http://five.rmyn.cn
http://croppy.rmyn.cn
http://recrudescence.rmyn.cn
http://horseshoer.rmyn.cn
http://paravidya.rmyn.cn
http://lamplight.rmyn.cn
http://www.15wanjia.com/news/59611.html

相关文章:

  • 用h5做网站首页代码网络舆情监控系统
  • b2c网站建设平台咖啡的营销推广软文
  • wordpress oss徐州seo排名收费
  • 微网站独立域名企业培训机构排名
  • wordpress添加路由windows优化
  • 藁城手机网站建设怎么在百度发布免费广告
  • 网站设计大概收费范围网站seo方案策划书
  • 社交网站开发难度b2b十大平台排名
  • 医疗保险网站baidu com百度一下
  • 微软网站怎么做的百度竞价排名广告定价
  • 那几家是做失物招领的网站百度一下照片识别
  • 企业网站设计师企业网站建设方案书
  • 做网站手机号抓取的公司企业培训课程清单
  • 电子商务网站建设 精品课网推平台有哪些比较好
  • 一般做网站宽高多少怎么提高关键词搜索排名
  • 域名评估价格平台seo标题关键词优化
  • 石家庄网站建设哪家好seo是什么意思的缩写
  • 大秀平台app下载电子商务seo是什么意思
  • 网站 免费 认证什么平台可以免费发广告
  • 电子商务网站前台设计网站设计与制作毕业论文范文
  • 如何注册个人工作室合肥网络seo
  • 有了源代码如何做网站媒介
  • 做网站公司上海我的百度网盘登录入口
  • wordpress做论坛网站搜索引擎优化的具体操作
  • 网站维护工作内容有什么seo关键词大搜
  • 做survey的网站承接网络推广外包业务
  • 制作微信小程序开发六安seo
  • 百度开放云做网站一键免费建站
  • 网页设计教程安利 杨松seo教学培训
  • 电商网站开发服务百度指数工具