Qt QML 雙ListView同步滾動
ListView {
id: roadView
width: Screen.width
height: 80
anchors{
bottom: listView.top
bottomMargin: 10
}
orientation: ListView.Horizontal
displayMarginBeginning: 3000
displayMarginEnd: 3000
Component {
id: readDelegate
RoadItem{
}
}
model: roadModel
delegate: readDelegate
// 主要代碼
ScrollBar.horizontal: ScrollBar {
id: road_sb
visible: false
}
}
ListView {
id: listView
width: Screen.width
height: 200
anchors{
left: parent.left
bottom: parent.bottom
right: parent.right
bottomMargin: 20
leftMargin: 10
rightMargin: 10
}
spacing: 12
clip: true
orientation: ListView.Horizontal
model: busNameList
delegate: BusNameItem {}
// 主要代碼
ScrollBar.horizontal: ScrollBar {
id: list_sb
visible: false
onPositionChanged: road_sb.position = position
}
onCurrentIndexChanged: {
roadView.itemAtIndex(0).pos_index = currentIndex
}
}
當時做這個需求時,百度找遍沒找到,自己琢磨用這個方式實現出來了,這個方法有不足,但是可以實現。