制作一个Flex DataGrid的滚动顺畅顺畅、Flex、DataGrid

2023-09-08 13:36:20 作者:孤刃野爹

我注意到,对于一个DataGrid的垂直滚动条的默认行为是滚动一行的时间。这是一个好主意,当行都是一样的,小(如显示文本单行),但变得非常难看,只要你有不同高度的行。

I've noticed that the default behaviour for a DataGrid's vertical scroll bar is to scroll one row at a time. This is all well and good when the rows are all uniform and small (e.g. displaying a single line of text), but gets really ugly as soon as you have rows with variable heights.

我很好奇,有没有一种方法,使DataGrid中滚动平稳?举例来说,有没有办法让DataGrid中滚动的像素,文本行等定数,而不是滚动一行的时间?

I'm curious, is there a way to make DataGrid scrolling "smooth"? For instance, is there a way to have the DataGrid scroll by a set number of pixels, lines of text, etc. rather than scrolling one row at a time?

到目前为止,唯一的解决办法我已经设法想出是把数据网格中的一个画布并有帆布做的滚动,而不是DataGrid中。这种方法的问题,不过,是尽快画布卷轴远远不够,DataGrid的标题滚动屏幕外。理想情况下,我想获得的画布的平滑滚动性,也保持在DataGrid标题可见。这可能吗?

So far, the only solution I've managed to come up with is to place the DataGrid in a Canvas and have the Canvas do the scrolling instead of the DataGrid. The issue with this approach, though, is that as soon as the Canvas scrolls far enough, the DataGrid headers scroll off-screen. Ideally, I'd like to get the smooth-scrolling nature of the Canvas, but also keep the DataGrid headers visible. Is that possible?

推荐答案

该方式的ItemRenderer在Flex 3的工作,使平滑滚动难以实现。基本上,Flex的回收滚出名单在列表的底部,用于新数据的显示对象顶部的项目渲染器。 Adobe的Flex中3实施最列表中的组件创建并为他们加油到屏幕上,而不是仅仅在屏幕增加了这些项目,让他们在弹出的平滑滚动不可用。我不知道为什么他们不可能以类似的方式完成它的项目+/-一个位置高于或低于当前的滚动窗格,但他们没有,而我们在默认情况下坚持了粘滚动。

The way that ItemRenderer's work in Flex 3 makes smooth scrolling difficult to achieve. Basically Flex recycles item renderers scrolled off of the top of the list as the display objects used for new data at the bottom of the list. Adobe's implementation of most list components in Flex 3 creates and adds these items as they come on to the screen rather than just off the screen, so they "pop in" and smooth scrolling isn't available. I'm not sure why they couldn't have done it in a similar manner for items +/- one position above or below the current scroll pane, but they didn't, and we're stuck with sticky scrolling by default.

的变通办法确实存在,虽然你已经注意到一个(丢弃数据网格到画布)否定了节能项目渲染意图的显示对象,并会导致性能开销。这在Flex 4的将被固定于大多数基于列表Flex组件,尽管它不会立即对数据网格固定。在DataGrid / AdvancedDataGrid组件是由总部设在印度一个独立的团队维护,我最后一次听到,所以它往往是有点落后了SDK的其余部分。

Work-arounds do exist, though the one you've noted (dropping the datagrid into a canvas) negates the display-object saving intention of item renderers and incurs a performance cost. This will be fixed for most list-based Flex components in Flex 4, though it won't be fixed immediately for DataGrid. The DataGrid / AdvancedDataGrid component is maintained by a separate team based in India, last time I heard, and so it tends to be a bit behind the rest of the SDK.

我建议你尝试类似的东西来这个实现的平滑滚动列表由Alex Harui 。我不知道它究竟会如何工作的DataGrid或的AdvancedDataGrid,但是这是最直观的方法我能想到的正确决策列表滚动。

I'd recommend trying something similar to this implementation of a smooth-scrolling list by Alex Harui. I'm not sure exactly how well it'd work for DataGrid or AdvancedDataGrid, but this is the most intuitive technique I can think of for making the list scroll correctly.