我有一个使用ListCell
来显示其项目的ListView
(水平方向)。这些细胞是Canvas
。当列表中放置了足够多的项目时,将激活垂直和水平ScrollBar
。当发生这种情况时,单元格的部分内容会被水平滚动条裁剪(在底部)。
我们如何设置(或调整)列表视图的高度,以便当滚动条出现时不会发生裁剪?它们是检测滚动条何时变得可见的方法吗?我们能确定滚动条的高度并简单地使列表的高度足够高吗?
我已经尝试了几种方法,通过在列表视图和列表视图单元格中更改侦听器。但这些似乎都不起作用。
提亚
发布于 2019-03-17 04:17:33
我想出了以下解决方案:添加事件侦听器-每次添加、删除或替换元素时,调整ListView的高度。调整大小时,请检查是否只有垂直和/或水平滚动条。如果只存在垂直滚动条,则使用其高度和插入来获取单元格高度。如果水平滚动条也存在,也添加它的高度(拇指的高度)。下面是相关的代码片段(在Scala中):
def extendHeight(thumbnails: ListView[String], vertical: Option[ScrollBar], horizontal: Option[ScrollBar]): Unit = {
(vertical, horizontal) match {
case (None, None) => ()
case (None, Some(_)) => ()
case (Some(v), None) =>
resizeHeight(thumbnails, v, 0)
case (Some(v), Some(h)) =>
val extra = if (h.isVisible) h.getHeight else 0
resizeHeight(thumbnails, v, extra)
}
}
def resizeToFrame(thumbnails: ListView[String]): Unit = {
val (vertical, horizontal) = PStoryBoardUX.getScrollBars(thumbnails)
PStoryBoardUX.extendHeight(thumbnails, vertical, horizontal)
}
thumbnails.getItems.addListener( new ListChangeListener[String] {
override def onChanged(c: Change[_ <: String]): Unit = {
javafx.application.Platform.runLater( () => {
// At thus point in time the scrollbars have not been updated
// So we don't know if they will be active or not. Force this
thumbnails.layout()
// Now resize to remove the visible scrollbars
resizeToFrame(thumbnails)
})
}
})
https://stackoverflow.com/questions/55082418
复制相似问题