HarmonyOS Tabs的tabBar如何让右边不贴边显示?

HarmonyOS  Tabs的tabBar如何让右边不贴边显示?

HarmonyOS
2024-09-24 12:10:42
浏览
收藏 0
回答 1
待解决
回答 1
按赞同
/
按时间
Heiang

tabBar右边不贴边显示目前做不到,做了一个规避。

@Entry  
@Component  
struct Index {  
  @StorageLink('IndexPage') currentPageIndex: number = 0;  
  build() {  
    Stack({ alignContent: Alignment.Top }) {  
      Image($r('app.media.ic_app_background'))//背景图  
        .width('100%')  
        .height(220)  
        .objectFit(ImageFit.Fill)  
      Row() {  
        Stack({ alignContent: Alignment.TopEnd }) {  
          Tabs({ barPosition: BarPosition.Start }) {  
            ForEach(buttonInfo, (item: ButtonInfoModel, index?: number) => {  
              TabContent() {  
                Home()  
              }  
              .tabBar(this.BottomNavigation(item))  
            }, (item: Resource) => JSON.stringify(item))  
  
          }  
          .backgroundColor('#00000000')  
          .barWidth('100%')  
          .barHeight(50 )  
          .vertical(false)  
          .barMode(BarMode.Scrollable,{margin:10})  
          .scrollable(false)  
          .onChange((index: number) => {  
            this.currentPageIndex = index;  
          })  
          Row(){  
            //后续用半透明的图片替换  
            Row(){}.width('12vp').height('20vp').backgroundColor('#44000000')  
            Image($r('app.media.ic_more'))//这个icon要带背景色  
              .width('16vp')  
              .height('20vp')  
              .onClick(() => {  
                this.currentPageIndex = 0;  
              })  
          }  
          .margin({top:'17vp' })  
        }  
      }  
      .width('100%')  
      .padding({ left: 12, right: 12})  
    }  
    .backgroundColor('#00000000')  
  }  
  
  @Builder BottomNavigation(button: ButtonInfoModel) {  
    Column({ space: 2}) {  
      Text(button.title)  
        .fontColor(this.currentPageIndex === button.index ? '#121212' : '#d1d2d3')  
        .opacity(this.currentPageIndex === button.index ? 1 : 0.4 )  
        .fontWeight(this.currentPageIndex === button.index ? 700 : 400)  
        .fontSize(this.currentPageIndex === button.index ? 18 : 16)  
        .textAlign(TextAlign.Center)  
    }  
    .backgroundColor('#00000000')  
    .width(60)  
    .height('100%')  
    .alignItems(HorizontalAlign.Center)  
    .justifyContent(FlexAlign.Center)  
  }  
}  
  
class ButtonInfoModel {  
  index: number = 0;  
  title: string = '';  
}  
  
const buttonInfo: ButtonInfoModel[] = [  
  { index: 0, title: '精选' },  
  { index: 1, title: '政声' },  
  { index: 2, title: '成都' },  
  { index: 3, title: '专题' },  
  { index: 4, title: '观察' },  
  { index: 5, title: '都市圈' },  
  { index: 6, title: '人文' }  
]  
  
@Component  
export struct Home {  
  @State messgae:string = '精选'  
  build() {  
    Column(){Text('首页内容:' + this.messgae)}  
    .height('100%')  
    .width('100%')  
    .padding({ left: 12, right: 12})  
    .backgroundColor('#00f1f1f1')//透明度为全透明  
  }  
}
分享
微博
QQ
微信
回复
2024-09-24 15:31:36
相关问题
HarmonyOS Tabs组件tabBar宽度问题
258浏览 • 1回复 待解决
HarmonyOS 如何设定tabs组件tabbar样式
279浏览 • 1回复 待解决
HarmonyOS tabstabBar怎么居左
240浏览 • 1回复 待解决
如何TabstabBar,添加其他组件
274浏览 • 1回复 待解决
关于Tabs里面tabBar样式问题
73浏览 • 2回复 待解决
如何日历显示是农历日期?
243浏览 • 1回复 待解决
Tabs如何才能居左显示
723浏览 • 1回复 待解决
如何变量名中包含“-”
1336浏览 • 1回复 待解决
Tab导航栏tabbar子组件突出上沿显示
1931浏览 • 1回复 待解决