如何设置Tabs的末尾由透明到不透明的渐变效果

如何设置Tabs的末尾由透明到不透明的渐变效果

HarmonyOS
2024-03-17 15:20:43
869浏览
收藏 0
回答 1
回答 1
按赞同
/
按时间
电子土豆片
  • 方案一:通过List组件结合linearGradient自定义实现。
@Entry 
@Component 
struct ListExample { 
  @State arr: number[] = [1, 2, 3, 4, 5, 6, 7, 8, 9]; 
  private scroller: Scroller = new Scroller(); 
 
  build() { 
    Stack() { 
      List({ space: 10 }) { 
        ForEach(this.arr, (item: string) => { 
          ListItem() { 
            Text("中国潮色") 
              .width(100) 
              .height(64) 
              .fontColor(Color.White) 
              .backgroundColor(Color.Black) 
              .textAlign(TextAlign.Center) 
          } 
        }, (item: string) => item); 
      } 
      .listDirection(Axis.Horizontal) 
      .scrollBar(BarState.Off) 
      .padding({ top: 20, bottom: 20 }) 
      .width("80%") 
      .height("100%") 
 
      Stack() { 
 
      } 
      .linearGradient({ 
        angle: 90, 
        colors: [[0x000000, 0.0], ['rgba(0,0,0,0)', 0.1], ['rgba(0,0,0,0)', 0.9], [0x000000, 1.0]] 
      }) 
      .width("80%") 
      .height("100%") 
      .hitTestBehavior(HitTestMode.None) 
    }.height(100).width('100%').backgroundColor(Color.Black) 
  } 
}
  • 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.
  • 方案二:API10起可以通过Tabs组件fadingEdge属性来实现边缘渐变消失的效果。
@Entry 
@Component 
struct TabsOpaque { 
  @State message: string = 'Hello World'; 
  private controller: TabsController = new TabsController(); 
  private controller1: TabsController = new TabsController(); 
  @State selfFadingFade: boolean = true; 
 
  build() { 
    Column() { 
      Button('子页签设置渐隐').width('100%').margin({ bottom: '12vp' }) 
        .onClick((event?: ClickEvent) => { 
          this.selfFadingFade = true; 
        }) 
      Button('子页签设置不渐隐').width('100%').margin({ bottom: '12vp' }) 
        .onClick((event?: ClickEvent) => { 
          this.selfFadingFade = false; 
        }) 
      Tabs({ barPosition: BarPosition.End, controller: this.controller }) { 
        TabContent() { 
          Column().width('100%').height('100%').backgroundColor(Color.Pink) 
        }.tabBar('pink') 
 
        TabContent() { 
          Column().width('100%').height('100%').backgroundColor(Color.Yellow) 
        }.tabBar('yellow') 
 
        TabContent() { 
          Column().width('100%').height('100%').backgroundColor(Color.Blue) 
        }.tabBar('blue') 
 
        TabContent() { 
          Column().width('100%').height('100%').backgroundColor(Color.Green) 
        }.tabBar('green') 
 
        TabContent() { 
          Column().width('100%').height('100%').backgroundColor(Color.Green) 
        }.tabBar('green') 
 
        TabContent() { 
          Column().width('100%').height('100%').backgroundColor(Color.Green) 
        }.tabBar('green') 
 
        TabContent() { 
          Column().width('100%').height('100%').backgroundColor(Color.Green) 
        }.tabBar('green') 
 
        TabContent() { 
          Column().width('100%').height('100%').backgroundColor(Color.Green) 
        }.tabBar('green') 
      } 
      .vertical(false) 
      .scrollable(true) 
      .barMode(BarMode.Scrollable) 
      .barHeight(80) 
      .animationDuration(400) 
      .onChange((index: number) => { 
        console.info(index.toString()); 
      }) 
      .fadingEdge(this.selfFadingFade) 
      .height('30%') 
      .width('100%') 
 
      Tabs({ barPosition: BarPosition.Start, controller: this.controller1 }) { 
        TabContent() { 
          Column().width('100%').height('100%').backgroundColor(Color.Pink) 
        }.tabBar('pink') 
 
        TabContent() { 
          Column().width('100%').height('100%').backgroundColor(Color.Yellow) 
        }.tabBar('yellow') 
 
        TabContent() { 
          Column().width('100%').height('100%').backgroundColor(Color.Blue) 
        }.tabBar('blue') 
 
        TabContent() { 
          Column().width('100%').height('100%').backgroundColor(Color.Green) 
        }.tabBar('green') 
 
        TabContent() { 
          Column().width('100%').height('100%').backgroundColor(Color.Green) 
        }.tabBar('green') 
 
        TabContent() { 
          Column().width('100%').height('100%').backgroundColor(Color.Green) 
        }.tabBar('green') 
      } 
      .vertical(true) 
      .scrollable(true) 
      .barMode(BarMode.Scrollable) 
      .barHeight(200) 
      .barWidth(80) 
      .animationDuration(400) 
      .onChange((index: number) => { 
        console.info(index.toString()); 
      }) 
      .fadingEdge(this.selfFadingFade) 
      .height('30%') 
      .width('100%') 
    } 
    .padding({ top: '24vp', left: '24vp', right: '24vp' }) 
  } 
}
  • 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.
  • 93.
  • 94.
  • 95.
  • 96.
  • 97.
  • 98.
  • 99.
  • 100.
  • 101.
  • 102.
  • 103.
  • 104.

参考链接

Tabs组件

分享
微博
QQ
微信
回复
2024-03-18 20:58:35
相关问题
HarmonyOS 如何实现透明渐变效果
702浏览 • 1回复 待解决
如何设置组件透明效果
2835浏览 • 1回复 待解决
HarmonyOS 背景半透明渐变怎么设置
934浏览 • 1回复 待解决
HarmonyOS page页面如何设置透明效果
729浏览 • 1回复 待解决
HarmonyOS 如何实现半透明遮罩效果
1006浏览 • 1回复 待解决
如何设置透明页面
590浏览 • 1回复 待解决
HarmonyOS UIAbility如何设置透明背景
761浏览 • 1回复 待解决
SideBarContainer如何设置透明度?
2984浏览 • 1回复 待解决
如何设置卡片背景为透明
3666浏览 • 1回复 待解决
设置XComponent组件为透明
1238浏览 • 1回复 待解决
XComponent 怎么设置透明
2893浏览 • 1回复 待解决
HarmonyOS 如何设置页面背景半透明
744浏览 • 1回复 待解决
HarmonyOS 如何设置背景透明
681浏览 • 1回复 待解决
HarmonyOS 如何设置颜色透明
1651浏览 • 1回复 待解决