所以这就是这种情况。我正在使用 JavaFXPorts 实现一个应用程序,我想创建一个圆形的 ToggleButton。然后将此按钮放置在 GridPane 上,该 GridPane 还包含一个包装在 ScrollPane 中的 HBox。为了简单起见,我只是给树提供了 GridPane 拥有的节点。
GridPane
|___________ ToggleButton
|___________ ScrollPane
|__________ HBox
|_______ 20+ Images here
所以,当我在 iPhone 5 上编译它时,一切都运行得非常顺利。我可以水平滚动 HBox 并查看其中的图像。
但是,当我使用下面的 CSS 代码时,事情开始发生变化。滚动的性能下降到它变得滞后的地步。在使用样式后,我注意到问题是“-fx-(背景/边框)-半径”样式的原因。我认为这可能是一个错误。我也尝试过缓存节点,这可以提高速度,但仍然滞后。
请注意,在 iPhone 6 上运行相同的应用程序,它运行良好。
.rounded_button {
-fx-background-color: transparent;
-fx-background-insets: 0;
-fx-text-fill: black;
-fx-border-color: lightgray;
-fx-font-size: 0.9em;
-fx-pref-height: 33px;
-fx-background-radius: 0em 1.5em 1.5em 0em;
-fx-border-radius: 0 1.5em 1.5em 0;
}
我还启用了脉冲记录器,这是输出:
PULSE: 556 [73887ms:327ms]
T1 (-73886 +73887ms): Layout Pass
T1 (0 +14ms): CSS Pass
T1 (14 +2ms): Layout Pass
T1 (16 +0ms): Update bounds
T1 (17 +0ms): Waiting for previous rendering
T1 (17 +0ms): Copy state to render graph
T7 (18 +0ms): Dirty Opts Computed
T7 : 2 different dirty regions to render
T7 : Dirty Region 0: RectBounds { minX:183.0, minY:157.0, maxX:219.0, maxY:180.0} (w:36.0, h:23.0)
T7 : Render Root Path 0: [com.sun.javafx.sg.prism.NGRegion@578c420, com.sun.javafx.sg.prism.NGRegion@56314d0, com.sun.javafx.sg.prism.NGRegion@5631420, com.sun.javafx.sg.prism.NGRegion@4d03420, com.sun.javafx.sg.prism.NGRegion@adca630, com.sun.javafx.sg.prism.NGRegion@4d03160, com.sun.javafx.sg.prism.NGRegion@4d030b0, com.sun.javafx.sg.prism.NGRegion@49294d0, com.sun.javafx.sg.prism.NGRegion@49296e0]
T7 : Dirty Region 1: RectBounds { minX:310.0, minY:63.0, maxX:319.0, maxY:519.0} (w:9.0, h:456.0)
T7 : Render Root Path 1: [com.sun.javafx.sg.prism.NGRegion@578c420, com.sun.javafx.sg.prism.NGRegion@56314d0, com.sun.javafx.sg.prism.NGRegion@5631420, com.sun.javafx.sg.prism.NGRegion@4d03420, com.sun.javafx.sg.prism.NGRegion@adca630, com.sun.javafx.sg.prism.NGRegion@4d03160]
T7 (18 +0ms): Render Roots Discovered
T7 : Slow background path for null
T7 : Slow shape path for null
T7 : Slow background path for null
T7 : Slow shape path for null
T7 : Slow background path for null
T7 (18 +305ms): Painting
T7 (324 +0ms): Painting
T7 (325 +2ms): Presenting
Counters:
CacheFilter rebuilding: 3
NGRegion renderBackgroundShape slow path: 2
NGRegion renderBackgrounds slow path: 3
Nodes rendered: 57
Nodes visited during render: 71
没有-fx-background-radius,-fx-border-radius:
PULSE: 1493 [89717ms:37ms]
T1 (-89717 +89717ms): Layout Pass
T1 (0 +13ms): CSS Pass
T1 (13 +1ms): Layout Pass
T1 (15 +0ms): Update bounds
T1 (16 +0ms): Waiting for previous rendering
T1 (16 +0ms): Copy state to render graph
T7 (16 +0ms): Dirty Opts Computed
T7 : 2 different dirty regions to render
T7 : Dirty Region 0: RectBounds { minX:183.0, minY:157.0, maxX:219.0, maxY:180.0} (w:36.0, h:23.0)
T7 : Render Root Path 0: [com.sun.javafx.sg.prism.NGRegion@542b420, com.sun.javafx.sg.prism.NGRegion@578a370, com.sun.javafx.sg.prism.NGRegion@578a2c0, com.sun.javafx.sg.prism.NGRegion@556e840, com.sun.javafx.sg.prism.NGRegion@556e0b0, com.sun.javafx.sg.prism.NGRegion@556e420, com.sun.javafx.sg.prism.NGRegion@556e370, com.sun.javafx.sg.prism.NGRegion@4c9f580, com.sun.javafx.sg.prism.NGRegion@4c9f630, com.sun.javafx.sg.prism.NGRegion@4c9f790, com.sun.javafx.sg.prism.NGRegion@4c9f8f0]
T7 : Dirty Region 1: RectBounds { minX:310.0, minY:63.0, maxX:319.0, maxY:519.0} (w:9.0, h:456.0)
T7 : Render Root Path 1: [com.sun.javafx.sg.prism.NGRegion@542b420, com.sun.javafx.sg.prism.NGRegion@578a370, com.sun.javafx.sg.prism.NGRegion@578a2c0, com.sun.javafx.sg.prism.NGRegion@556e840, com.sun.javafx.sg.prism.NGRegion@556e0b0, com.sun.javafx.sg.prism.NGRegion@556e420]
T7 (16 +0ms): Render Roots Discovered
T7 : Slow background path for null
T7 : Slow shape path for null
T7 : Slow background path for null
T7 : Slow shape path for null
T7 (17 +17ms): Painting
T7 (35 +0ms): Painting
T7 (35 +1ms): Presenting
Counters:
CacheFilter rebuilding: 3
NGRegion renderBackgroundShape slow path: 2
NGRegion renderBackgrounds slow path: 2
Nodes rendered: 57
Nodes visited during render: 71
Pulse 在没有样式的情况下在37 毫秒内完成。
先感谢您
更新
您可以从这里下载源代码。
下面是 iPhone 5 的屏幕截图。当水平滚动包含按钮 ABC、BCD、CDE 等的 HBox 时,事情开始变得迟钝。在右下角的图像中,是我删除 .css 样式后的屏幕截图,并且滚动效果很好。