【鸿蒙应用开发高手之路】06_自适应布局之延伸能力
所谓延伸能力,指的是:当父容器的尺寸发生变化时,子组件按照先后顺序随之显示或隐藏。
@Entry@Componentstruct Extension1 { private names: string[] = ['0', '1', '2', '3', '4', '5', '6', '7', '8', '9'] build() { List({ space: 50 }) { ForEach(this.names, (name) => { ListItem() { Column() { Image($r("app.media.icon")).width(150).height(150) Text(name).width(150).height(150).fontSize(100).textAlign(TextAlign.Center) } } }) } .listDirection(Axis.Horizontal) .height(300) }}
@Entry@Componentstruct Extension2 { private scroller: Scroller = new Scroller() private names: string[] = ['0', '1', '2', '3', '4', '5', '6', '7', '8', '9'] build() { Scroll(this.scroller) { Row({ space: 50 }) { ForEach(this.names, (name) => { Column() { Image($r("app.media.icon")).width(150).height(150) Text(name).width(150).height(150).fontSize(100).textAlign(TextAlign.Center) } }) } } .scrollable(ScrollDirection.Horizontal) }}