Skip to content

ListView

ListView 类似 ScrollView,但它应该有一个 for 元素,内容会 自动排列为列表。

在 ListView 中,元素仅在可见时才会实例化,这保证了在拥有几乎无限数量项时性能稳定。

ScrollView 更适合自由形式的内容。

import { ListView, VerticalBox } from "std-widgets.slint";
export component Example inherits Window {
width: 150px;
height: 150px;
VerticalBox {
ListView {
for data in [
{ text: "Blue", color: #0000ff, bg: #eeeeee},
{ text: "Red", color: #ff0000, bg: #eeeeee},
{ text: "Green", color: #00ff00, bg: #eeeeee},
{ text: "Yellow", color: #ffff00, bg: #222222 },
{ text: "Black", color: #000000, bg: #eeeeee },
{ text: "White", color: #ffffff, bg: #222222 },
{ text: "Magenta", color: #ff00ff, bg: #eeeeee },
{ text: "Cyan", color: #00ffff, bg: #222222 },
] : Rectangle {
height: 30px;
background: data.bg;
width: parent.width;
Text {
x: 0;
text: data.text;
color: data.color;
}
}
}
}
}
slint

与 ScrollView 相同。

与 ScrollView 相同。

plaintext

© 2026 SixtyFPS GmbH