/*
* Copyright (c) 2026 Huawei Device Co., Ltd.
* Licensed under the Apache License, Version 2.0 (the 'License');
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
// [Start RowLayoutAlgorithm]
import {
DynamicLayout, DynamicLayoutAttribute, RowLayoutAlgorithm, LengthMetrics
} from '@kit.ArkUI';
@Entry
@ComponentV2
struct RowLayoutExample {
@Local algorithm: RowLayoutAlgorithm = new RowLayoutAlgorithm({
space: LengthMetrics.vp(10),
alignItems: VerticalAlign.Top,
justifyContent: FlexAlign.Start,
isReverse: false
});
build() {
Column({ space: 10 }) {
DynamicLayout(this.algorithm) {
Text('Item 1')
.width(80)
.height(40)
.fontSize(14)
.backgroundColor(0xF5DEB3)
Text('Item 2')
.width(80)
.height(40)
.fontSize(14)
.backgroundColor(0xD2B48C)
Text('Item 3')
.width(80)
.height(40)
.fontSize(14)
.backgroundColor(0xF5DEB3)
}
.width('100%')
.height(80)
.backgroundColor(0xEFEFEF)
Row({ space: 10 }) {
Button('修改间距')
.fontSize(14)
.onClick(() => {
this.algorithm.space = LengthMetrics.vp(20);
})
Button('反转排列')
.fontSize(14)
.onClick(() => {
this.algorithm.isReverse = !this.algorithm.isReverse;
})
}
Row({ space: 10 }) {
Button('竖直居中')
.fontSize(14)
.onClick(() => {
this.algorithm.alignItems = VerticalAlign.Center;
})
Button('水平居中')
.fontSize(14)
.onClick(() => {
this.algorithm.justifyContent = FlexAlign.Center;
})
}
}
.padding(20)
}
}
// [End RowLayoutAlgorithm]