社区运营|
HarmonyOS 5
如何设置Tabs的末尾由透明到不透明的渐变效果
如何设置Tabs的末尾由透明到不透明的渐变效果
1
1
浏览173 发布于2024-03-20 03:08广东
全部评论
最多点赞
最新发布
最早发布

方案一:通过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)
}
}
方案二: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楼回复于2024-03-20 03:10 来自广东
写回答
新增插入模板功能
一键使用模板,快速填写内容,轻松发帖~
知道了
- 为了保障您的信息安全,请勿上传您的敏感个人信息(如您的密码等信息)和您的敏感资产信息(如关键源代码、签名私钥、调试安装包、业务日志等信息),且您需自行承担由此产生的信息泄露等安全风险。
- 如您发布的内容为转载内容,请注明内容来源。
我要发帖子
相关推荐
换一批
1
HarmonyOS tabs与scroll滑动冲突 (API12+)
2
HarmonyOS Tabs嵌套,内外层联动不丝滑,如何解决?(API12+)
3
HarmonyOS 使用手势拦截增强onGestureRecognizerJudgeBegin,嵌套tabs里的web页面手势无法滑动外层tabs组件 (API12+)
4
HarmonyOS Scroll里面的Tabs吸顶取消的问题 (API12+)
5
导航条边缘文字透明渐变效果实现
6
HarmonyOS TabBar的透明模糊效果如何实现 (API12+)
7
HarmonyOS 如何实现多行文字最后一行透明渐变效果,部分文字有渐变色 (API12+)
8
HarmonyOS 如何实现多行文字最后一行透明渐变效果 (API12+)
了解社区公约,与您携手共创和谐专业的开发者社区。




































苏公安网备 32011402010933号