HarmonyOS Tabs组件标题长度如何自适应
如何设置能使标题长度自适应,每个标题的间距固定,代码如下:
@Component
export struct LUACHomeMainRecommendView {
@Prop recommendModel: LUACHTObject<LUACHTRecommendInfoData>
@State currentIndex: number = 0
@Builder
tabBuilder(index: number, name?: string) {
RelativeContainer() {
Text(name)
.fontColor(this.currentIndex === index ? $r('app.color.lucc_ui_color_222222') :
$r('app.color.luac_home_tab_color_758190'))
.fontSize(16)
.textAlign(TextAlign.Center)
.width('100%')
.maxLines(1)
.fontWeight(FontWeight.Bold)
.alignRules({
middle: { anchor: '__container__', align: HorizontalAlign.Center },
top: { anchor: '__container__', align: VerticalAlign.Top },
})
.margin({ top: 8 })
.id('title')
Image($r('app.media.luac_home_tab_progressline'))
.width(65)
.height(4)
.opacity(this.currentIndex === index ? 1 : 0)
.alignRules({
middle: { anchor: 'title', align: HorizontalAlign.Center },
bottom: { anchor: '__container__', align: VerticalAlign.Bottom },
})
.margin({ bottom: 8 })
.id('image')
}
.width('100%')
.margin({
top: 10,
bottom: 0,
left: 10,
right: 10
})
}
build() {
Column() {
if (this.recommendModel.data && this.recommendModel.data.length > 0) {
Tabs({ barPosition: BarPosition.Start }) {
ForEach(this.recommendModel.data, (item: LUACHTRecommendInfoData, index: number) => {
TabContent() {
Row() {
Text(item.tabName)
.height(182)
.fontSize(20)
}
.backgroundColor(Color.Orange)
.justifyContent(FlexAlign.Center)
.width('100%')
.height('100%')
}.tabBar(this.tabBuilder(index, item.tabName))
}, (item: LUACHTRecommendInfoData, index: number) => JSON.stringify(item) + index)
}
.vertical(false)
.barMode(BarMode.Scrollable, { margin: 10, nonScrollableLayoutStyle: LayoutStyle.SPACE_BETWEEN_OR_CENTER })
.fadingEdge(false)
// .barWidth(80)
// .barWidth('100%')
.barHeight(44)
.animationDuration(300)
.onAnimationStart((index: number, targetIndex: number) => {
this.currentIndex = targetIndex;
})
.width('100%')
.height('100%')
}
}.width('100%')
}
}
- 1.
- 2.
- 3.
- 4.
- 5.
- 6.
- 7.
- 8.
- 9.
- 10.
- 11.
- 12.
- 13.
- 14.
- 15.
- 16.
- 17.
- 18.
- 19.
- 20.
- 21.
- 22.
- 23.
- 24.
- 25.
- 26.
- 27.
- 28.
- 29.
- 30.
- 31.
- 32.
- 33.
- 34.
- 35.
- 36.
- 37.
- 38.
- 39.
- 40.
- 41.
- 42.
- 43.
- 44.
- 45.
- 46.
- 47.
- 48.
- 49.
- 50.
- 51.
- 52.
- 53.
- 54.
- 55.
- 56.
- 57.
- 58.
- 59.
- 60.
- 61.
- 62.
- 63.
- 64.
- 65.
- 66.
- 67.
- 68.
- 69.
- 70.
- 71.
- 72.
- 73.
- 74.
- 75.
- 76.
HarmonyOS
赞
收藏 0
回答 1
相关问题
HarmonyOS Tabs组件,TabContent的高度无法自适应内容组件高度
1144浏览 • 1回复 待解决
Web组件如何实现高度自适应?
1746浏览 • 1回复 待解决
Grid组件如何实现高度自适应
4164浏览 • 1回复 待解决
HarmonyOS Grid 组件如何根据子元素自适应高度?
795浏览 • 1回复 待解决
HarmonyOS Text组件如何实现文字大小自适应?
1710浏览 • 1回复 待解决
HarmonyOS web组件怎么自适应高度
754浏览 • 1回复 待解决
HarmonyOS Grid组件能否高度自适应
769浏览 • 1回复 待解决
HarmonyOS 自适应父组件高度问题
1870浏览 • 1回复 待解决
HarmonyOS web组件自适应高度问题
1803浏览 • 1回复 待解决
HarmonyOS 自定义弹窗中放Web组件, 弹窗高度不能自适应, Web高度不能自适应
619浏览 • 1回复 待解决
HarmonyOS gridItem不能根据内部组件自适应大小
505浏览 • 1回复 待解决
HarmonyOS RelativeContainer如何实现自适应自组件宽高?
771浏览 • 1回复 待解决
HarmonyOS Grid组件能否自适应内容高度?
673浏览 • 1回复 待解决
HarmonyOS RichText自适应高度
758浏览 • 1回复 待解决
HarmonyOS Text无法自适应
622浏览 • 1回复 待解决
arktsUI组件的自适应要怎么?
1186浏览 • 1回复 待解决
HarmonyOS grid如何自适应宽度
854浏览 • 1回复 待解决
HarmonyOS webview如何设置自适应
1423浏览 • 1回复 待解决
HarmonyOS 高度自适应
1052浏览 • 1回复 待解决
HarmonyOS web组件如何实现根据html字符内容高度自适应
847浏览 • 1回复 待解决
HarmonyOS RelativeContainer、List组件怎么实现自适应内容高度
2302浏览 • 2回复 待解决
HarmonyOS 如何实现自适应web的高度
641浏览 • 1回复 待解决
HarmonyOS RelativeContainer无法自适应高度
1268浏览 • 1回复 待解决
HarmonyOS RichText能否自适应高度
652浏览 • 1回复 待解决
HarmonyOS Web高度自适应问题
1604浏览 • 1回复 待解决
可参考文档示例6:https://developer.huawei.com/consumer/cn/doc/harmonyos-references-V5/ts-container-tabs-V5#示例6
可使用自定义tabbar,参考示例如下: