Android上的JavaFX ScrollPane - 太慢了 [英] JavaFX ScrollPane on Android - Too Slow

查看:233
本文介绍了Android上的JavaFX ScrollPane - 太慢了的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我刚编写了一个在JavaFX中使用滚动窗格的简单示例。只有一个ScrollPane放置在Scene中,ScrollPane包含一个带有大文本的Label组件。使用gradle我已经在Nexus 4 android设备上上传了应用程序。正如您从我上传的视频中看到的那样,滚动速度太慢了。我相信其他人也经历过这一点。任何有关如何将其更改为原生速度滚动的建议都非常受欢迎。

I have just coded a simple example of using a scrolling pane in JavaFX. Just one ScrollPane placed in the Scene, and the ScrollPane holds a Label component with a large text. Using gradle I have uploaded the app on a Nexus 4 android device. As you can see from the video I have uploaded, the scrolling is way too slow. I am sure others have experienced this. Any suggestion of how this can be changed to the native speed scroll is really much appreciated.

应用程序的源代码可以是从这里下载

Source code of the app can be downloaded from here.

AndroidFX.java

public class AndroidFX extends Application{

    public static void main(String[] args) {
        launch(args);
    }

    @Override
    public void start(Stage primaryStage) throws Exception {
        Parent mySearchListFXML = getFXMLPane("/fxml/ScrollPaneWithLabel.fxml");
        primaryStage.setScene(new Scene(mySearchListFXML));
        primaryStage.setWidth(Screen.getPrimary().getVisualBounds().getWidth()); primaryStage.setHeight(Screen.getPrimary().getVisualBounds().getHeight());     
        primaryStage.show();
    }

    public static Parent getFXMLPane(String url) throws IOException {
        URL location = AndroidFX.class.getResource(url);
        FXMLLoader fxmlLoader = new FXMLLoader();
        fxmlLoader.setLocation(location);
        Parent pane = fxmlLoader.load();
        return pane;
    }
}

ScrollPaneWithLabel.fxml

<?xml version="1.0" encoding="UTF-8"?>

<?import javafx.scene.*?>
<?import javafx.scene.control.*?>
<?import java.lang.*?>
<?import javafx.scene.layout.*?>

<ScrollPane fx:id="scrollPane" fitToWidth="true" hbarPolicy="NEVER" pannable="true" style="-fx-background: white;" xmlns="http://javafx.com/javafx/8" xmlns:fx="http://javafx.com/fxml/1">
   <content>
      <Label text="<VERY LARGE TEXT HERE>" wrapText="true" />
   </content>
</ScrollPane>


推荐答案

面临类似问题。 hidpi设备上的问题更严重,禁用属性文件中的hipdpi设置有帮助,但你必须为hidpi屏幕进行任何缩放。

Faced similar issues. The problem is worse on hidpi devices, disabling the hipdpi setting in the properties file helps but you will have to do any scaling your self for hidpi screens.

另一件事可能帮助是缓存字体。我相信javafx移植应用程序的最终结果更像是一个带有热点的大图像。滚动我认为只是告诉应用程序每次重绘整个图像。真是一个理论。缓存确实有帮助,但可以使您的文本看起来有点模糊。虽然我在缩放字体方面取得了一些成功,但将缓存设置为true然后缩小,通常x2和.5会产生相当不错的结果。使用em作为字体也有助于模糊文本。

Another thing that might help is caching the fonts. I believe the end result of a javafx ported application is more like a big image with hot spots. Scrolling I think is just telling the application to redraw the whole image every time. Just a theory really. Caching does help but can make your text look kinda fuzzy. Although I had some success in scaling the font large, setting the cache to true and then scale down, normally x2 and .5 gives pretty good results. Using em for the fonts helps the fuzzy text too.

如果你需要显示大量文本并且必须滚动,你可能会得到更好的结果显示它通过webview。我从来没有真正使用过它,但是我想可以在用本机浏览器窗口移植时替换它,所以我认为性能应该非常好。我猜他们有可能在javafx中写了一个html渲染器然后你会遇到同样的陷阱。

If you need to show a huge amount of text and it must be scrolled, you will probably get much better results displaying it through a webview. I haven't ever really used it to be honest, but I would imagine that it is replaced when ported with the native browser window so performance should be pretty good I think. I guess it is possible they wrote a html renderer in javafx and then you would run into the same pitfalls.

http://www.gluonhq.com 提供了一个名为charm,down和connect包的东西,它应该模仿本机应用程序。这听起来很有希望,我目前正在尝试获取更多信息,看看他们是否有解决这些类型的问题。如果我收到有关魅力的更多信息,我会在帖子中添加。

http://www.gluonhq.com is offering something called the charm, down, and connect package that is supposed to mimic native apps. It sounds promising and I am currently trying to get more info to see if they have solutions to these types of issues. I will add to the post if I receive any more info about charm.

这篇关于Android上的JavaFX ScrollPane - 太慢了的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆