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')//透明度为全透明  
  }  
}
  • 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.
  • 77.
  • 78.
  • 79.
  • 80.
  • 81.
  • 82.
  • 83.
  • 84.
  • 85.
  • 86.
  • 87.
  • 88.
  • 89.
  • 90.
  • 91.
  • 92.
分享
微博
QQ
微信
回复
2024-09-24 15:31:36
相关问题
HarmonyOS tabbar居左显示
583浏览 • 1回复 待解决
HarmonyOS 如何设定tabs组件tabbar样式
1431浏览 • 1回复 待解决
HarmonyOS Tabs组件tabBar宽度问题
1399浏览 • 1回复 待解决
HarmonyOS tabstabBar怎么居左
1173浏览 • 1回复 待解决
如何TabstabBar,添加其他组件
1519浏览 • 1回复 待解决
HarmonyOS Tabs 组件无法隐藏 tabbar
1418浏览 • 1回复 待解决
HarmonyOS tabstabbar整体位置调整
565浏览 • 1回复 待解决
Tabs组件tabBar,能否设置对齐方法?
1180浏览 • 1回复 待解决
关于Tabs里面tabBar样式问题
1029浏览 • 2回复 待解决