W3Cschool
恭喜您成為首批注冊(cè)用戶
獲得88經(jīng)驗(yàn)值獎(jiǎng)勵(lì)
滾動(dòng)條組件ScrollBar,用于配合可滾動(dòng)組件使用,如List、Grid、Scroll。
該組件從API Version 8開(kāi)始支持。后續(xù)版本如有新增內(nèi)容,則采用上角標(biāo)單獨(dú)標(biāo)記該內(nèi)容的起始版本。
ScrollBar(value: { scroller: Scroller, direction?: ScrollBarDirection, state?: BarState })
參數(shù):
參數(shù)名 | 參數(shù)類型 | 必填 | 參數(shù)描述 |
---|---|---|---|
scroller | 是 | 可滾動(dòng)組件的控制器。用于與可滾動(dòng)組件進(jìn)行綁定。 | |
direction | 否 | 滾動(dòng)條的方向,控制可滾動(dòng)組件對(duì)應(yīng)方向的滾動(dòng)。 默認(rèn)值:ScrollBarDirection.Vertical | |
state | 否 | 滾動(dòng)條狀態(tài)。 默認(rèn)值:BarState.Auto |
ScrollBar組件負(fù)責(zé)定義可滾動(dòng)區(qū)域的行為樣式,ScrollBar的子節(jié)點(diǎn)負(fù)責(zé)定義滾動(dòng)條的行為樣式。
滾動(dòng)條組件與可滾動(dòng)組件通過(guò)Scroller進(jìn)行綁定,且只有當(dāng)兩者方向相同時(shí),才能聯(lián)動(dòng),ScrollBar與可滾動(dòng)組件僅支持一對(duì)一綁定。
- // xxx.ets
- @Entry
- @Component
- struct ScrollBarExample {
- private scroller: Scroller = new Scroller()
- private arr: number[] = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15]
- build() {
- Column() {
- Stack({ alignContent: Alignment.End }) {
- Scroll(this.scroller) {
- Flex({ direction: FlexDirection.Column }) {
- ForEach(this.arr, (item) => {
- Row() {
- Text(item.toString())
- .width('80%')
- .height(60)
- .backgroundColor('#3366CC')
- .borderRadius(15)
- .fontSize(16)
- .textAlign(TextAlign.Center)
- .margin({ top: 5 })
- }
- }, item => item)
- }.margin({ right: 15 })
- }
- .width('90%')
- .scrollBar(BarState.Off)
- .scrollable(ScrollDirection.Vertical)
- ScrollBar({ scroller: this.scroller, direction: ScrollBarDirection.Vertical,state: BarState.Auto }) {
- Text()
- .width(20)
- .height(100)
- .borderRadius(10)
- .backgroundColor('#C0C0C0')
- }.width(20).backgroundColor('#ededed')
- }
- }
- }
- }
Copyright©2021 w3cschool編程獅|閩ICP備15016281號(hào)-3|閩公網(wǎng)安備35020302033924號(hào)
違法和不良信息舉報(bào)電話:173-0602-2364|舉報(bào)郵箱:jubao@eeedong.com
掃描二維碼
下載編程獅App
編程獅公眾號(hào)
聯(lián)系方式:
更多建議: