我有一个带有scrollView的WML应用程序,并且内部有一个listView。ListView的项目具有可变的高度。
我需要知道何时移动滚动条,实际上是何时在底部,何时不在。我的目标是仅在滚动在底部时将项目添加到listView时,将滚动保持在底部(positionviewatend())。如果不在底部,则不会使用positionViewAtend()。
我尝试过"播放"身高,contentheigh&有争议。有时它有效(滚动在底部时:contentheight == condety height),但是其他时候,condity的值会变为负值,而我的代码失败了...
有帮助吗?
非常感谢
迭戈
感谢J-P Nurmi,
我在几个属性更改中尝试了" Atyend",以检测滚动是否在底部
它似乎有效,然后我在" oncountchanged"中使用它,将滚动滚动放在底部
一旦所有ListView高度都充满了消息,但在一种情况下却不是:当传入消息是填充邮件的消息时ListView Height(第一次有争议不是'0')。
我不知道它是否清楚...
我简化了我的代码进行测试(包括代表),现在似乎是这样的:
FocusScope {
clip: true
id: focusScopeView
width: parent.width; height: parent.height
ScrollView {
width: parent.width; height: parent.height
ListView {
id: listTexts
width: parent.width; height: parent.height
property bool bScrolled: false
model: textsModel
delegate: Text { text: "Contact:t" + eventText }
onCountChanged: {
if (!bScrolled)
positionViewAtEnd();
}
onContentYChanged: {
bScrolled = !atYEnd;
if (atYEnd)
positionViewAtEnd()
}
onContentHeightChanged: {
if (!bScrolled)
positionViewAtEnd();
}
}
}
}
谢谢!
迭戈
计算失败的原因是,由于可变高度的代表,ListView
必须调整其来源。包括计算的来源将有助于获得正确的值,但是有一种更方便的方法来检查任何Flickable
是否是Atyend。
编辑:这是一个窍门,但是进行自动滚动的另一种方法(或更确切地说,以避免滚动需要)是将ListView.BottomToTop
用作垂直布局方向。然后,如果附加到末尾,请在模型开头插入新消息。这样,当新消息到达时,内容就可以保持对齐,而无需进行任何手动定位。不过,有一点收获。当内容少于拟合时,内容也将与底部对齐。
ListView {
onContentYChanged: {
if (contentY === contentHeight - height) {
console.log("scrolled to bottom");
}
}
}
ScrollView {
flickableItem.onContentYChanged: {
if (flickableItem.contentY === flickableItem.contentHeight - viewport.height) {
console.log("scrolled to bottom");
}
}
}
ListView {
ScrollBar.vertical: ScrollBar {
id: taskScroll
}
property bool atBottom: (taskScroll.position + taskScroll.size) == 1
}