- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我想要一些关于如何在用户按下按钮时为 Pane 实现幻灯片转换的指南,就像 Material Design 为滑动菜单所做的那样。
这是一个视频link这说明了我的需要。
我尝试了 ScaleTransition、TranslateTransition,但他们没有成功。
我试图实现它的方式效率不高。
// swipeMenuPane is builded in SceneBuilder and it is hidden,
// opacity = 0.0 and setX() = -getPrefWidth();
@FXML AnchorPane swipeMenuPane;
@FXML Button menuButton;
menuButton.setOnMouseClicked(e-> {
swipeMenuPane.setOpacity(1.0);
swipeTransition.play()
});
TranslateTransition swipeTransition = new TranslateTransition();
swipeTransition.setNode(swipeMenuPane);
swipeTransition.setDuration(Duration.millis(500));
swipeTransition.setToX(swipeMenuPane.getPrefWidth());
package com.helloworld;
import com.gluonhq.charm.glisten.animation.ShrinkExpandAnimation;
import javafx.application.Application;
import javafx.scene.Scene;
import javafx.scene.control.Button;
import javafx.scene.layout.AnchorPane;
import javafx.scene.layout.StackPane;
import javafx.stage.Stage;
public class HelloWorld extends Application {
ShrinkExpandAnimation anim;
@Override
public void start(Stage stage) {
Button btn = new Button("Click Me!");
btn.setOnMouseClicked(e-> {
System.out.println("swiping...");
anim.play();
});
AnchorPane pane = new AnchorPane();
pane.setStyle("-fx-background-color: coral");
pane.getChildren().add(btn);
// false to shrink or true to expand
anim = new ShrinkExpandAnimation(pane, false);
Scene scene = new Scene(new StackPane(pane), 640, 480);
stage.setScene(scene);
stage.show();
}
}
public class SwipeMenuDemo extends Application {
AnchorPane swapPane;
Button btnMenu;
boolean isExpanded = true;
@Override
public void start(Stage stage) {
Label swapPaneLabel = new Label("Expandable Pane");
swapPaneLabel.setMinWidth(0);
ImageView swapPaneImage = new ImageView("http://vignette1.wikia.nocookie.net/jfx/images/5/5a/JavaFXIsland600x300.png");
swapPaneImage.setLayoutY(100);
Label rootPaneLabel = new Label("Root Pane");
rootPaneLabel.setStyle("-fx-font-size: 60;");
rootPaneLabel.setLayoutX(180);
rootPaneLabel.setLayoutY(180);
swapPane = new AnchorPane();
swapPane.setPrefSize(640, 440);
swapPane.setMinWidth(0);
swapPane.setLayoutY(40);
swapPane.setStyle("-fx-background-color: coral; -fx-font-size: 52;");
swapPane.getChildren().addAll(swapPaneImage, swapPaneLabel);
btnMenu = new Button("Menu");
btnMenu.setLayoutX(5);
btnMenu.setLayoutY(5);
btnMenu.setOnMouseClicked(e -> {
if (isExpanded) hideSwapPane().play();
else showSwapPane().play();
});
Button btnClose = new Button("Close");
btnClose.setLayoutX(590);
btnClose.setLayoutY(5);
btnClose.setOnMouseClicked(e -> Platform.exit());
AnchorPane rootPane = new AnchorPane();
rootPane.setStyle("-fx-background-color: grey;");
rootPane.getChildren().addAll(btnMenu, btnClose, rootPaneLabel, swapPane);
Scene scene = new Scene(rootPane, 640, 480);
stage.setScene(scene);
stage.initStyle(StageStyle.UNDECORATED);
stage.show();
}
private Animation hideSwapPane() {
btnMenu.setMouseTransparent(true);
Animation collapsePanel = new Transition() {
{
setCycleDuration(Duration.millis(2500));
}
@Override
protected void interpolate(double fraction) {
swapPane.setPrefWidth(640 * (1.0 - fraction));
}
};
collapsePanel.setOnFinished(e-> {
isExpanded = false;
btnMenu.setMouseTransparent(false);
});
return collapsePanel;
}
private Animation showSwapPane() {
btnMenu.setMouseTransparent(true);
final Animation expandPanel = new Transition() {
{
setCycleDuration(Duration.millis(2500));
}
@Override
protected void interpolate(double fraction) {
swapPane.setPrefWidth(640 * fraction);
}
};
expandPanel.setOnFinished(e-> {
isExpanded = true;
btnMenu.setMouseTransparent(false);
});
return expandPanel;
}
}
最佳答案
我是示例视频的作者。我将重复我在视频评论中所做的回应:
“您应该将其视为 android 中的抽屉导航,JavaFX 中的抽屉导航将是 AnchorPane
有 2 个 child ,第一个 StackPane
相当于 FrameLayout
作为我们的主要内容,其中的转换 Pane 是根据左侧菜单中选择的项目制作的,最后是 ListView
作为我们的左侧菜单,负数 translateX
等于 Listview
宽度。然后当用户按下按钮时,您必须播放将 translateX
的值设置为 0
的动画。"
你不应该使用 prefWidth()
在两个动画的 interpolate 方法中(折叠面板,展开面板),由于子级不调整大小,边距排列是唯一的约束 AnchorPane
拥有。
看看我做的这个例子。
https://github.com/marconideveloper/leftsidemenuexample
public class FXMLDocumentController implements Initializable {
@FXML
private Button menu;
@FXML
private AnchorPane navList;
@Override
public void initialize(URL url, ResourceBundle rb) {
//navList.setItems(FXCollections.observableArrayList("Red","Yellow","Blue"));
prepareSlideMenuAnimation();
}
private void prepareSlideMenuAnimation() {
TranslateTransition openNav=new TranslateTransition(new Duration(350), navList);
openNav.setToX(0);
TranslateTransition closeNav=new TranslateTransition(new Duration(350), navList);
menu.setOnAction((ActionEvent evt)->{
if(navList.getTranslateX()!=0){
openNav.play();
}else{
closeNav.setToX(-(navList.getWidth()));
closeNav.play();
}
});
}
}
<AnchorPane xmlns:fx="http://javafx.com/fxml/1" id="AnchorPane" prefWidth="500" prefHeight="500" fx:controller="leftslidemenusample.FXMLDocumentController">
<children>
<ToolBar AnchorPane.topAnchor="0.0" AnchorPane.leftAnchor="0.0" AnchorPane.rightAnchor="0.0" minHeight="56.0" >
<Button text="menu" fx:id="menu" />
</ToolBar>
<StackPane fx:id="mainContent" style="-fx-background-color:rgba(0,0,0,0.30)" AnchorPane.bottomAnchor="0.0" AnchorPane.topAnchor="56.0" AnchorPane.leftAnchor="0.0" AnchorPane.rightAnchor="0.0" >
<children>
</children>
</StackPane>
<AnchorPane fx:id="navList" style="-fx-background-color:white" AnchorPane.topAnchor="56.0" AnchorPane.bottomAnchor="0.0" prefWidth="180.0" translateX="-180" >
<children>
<Label text="left side menu"/>
</children>
</AnchorPane>
</children>
</AnchorPane>
关于JavaFX:如何为 Pane 创建幻灯片动画效果(在透明舞台内),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31601900/
如图所示,上面的红色框是一个 GridBox,下面是一个带有 Splitpane (ListView) 和 Gridpane (2 Buttons) 的 VBox。我想要实现的是在单击按钮“隐藏>>"
使用 msfconsole 并搜索 linux x64 有效负载。 我遇到过舞台 Actor 、舞台和单曲?它们都有“reverse_tcp”,可以将连接反转回攻击者。然而我尝试查找舞台 Actor
我正在寻找一种将 3 个 LineCharts 放入单个窗口的方法。我的意思是我想让它们并排放置,或者一个在另一个下面。 我一直在寻找实现它的方法,但找不到任何东西。我试图搜索如何将多个场景放入一个阶
我有一个有效的 Web 功能,它使用 html5 视频和 Canvas 来访问设备相机的媒体流,然后拍照并在 Canvas 中渲染图像。效果很好,但我想使用 konvajs stage 而不是 can
我在解决这个问题时遇到了困难,并且我找不到我遇到的这个问题的正确答案。我希望将一个场景/阶段用作打开另一个场景/阶段的按钮,并且两者都通过相同的方法调用。完整的方法如下: public void c
我在 JavaFX 上有一个简单的应用程序,它实际上由几个 Pane 和按钮组成。我不知道如何在舞台调整大小时移动按钮。所以,我希望左下角的按钮即使在调整窗口大小时也始终可见。 这里是节点概览: 这里
来自 Swing 并且是 JavaFX 的新手,我尝试对 Java FX Stages 和 Scenes 进行子类化。但是我很快就遇到了问题,比如初始化过程中找不到我的子类场景的 init 方法。 所
How to animate or move window using clutter_actor_animate? Here's my code and it didn't work. clutte
有没有办法从关联的类 Controller 中获取 FXML 加载文件的 Stage/Window 对象? 特别是,我有一个模态窗口 Controller ,我需要舞台来关闭它。 最佳答案 我找不到解
我将工作代码分为 2 个文件以避免困惑。以前确实有效,但是将所有场景都放在一个类中是非常不愉快的。 以前,当您单击 Sprite 时,它会将您从菜单带到游戏。然后我将游戏组和游戏场景的代码提取到游戏类
我希望能够将 HTML 文本转换为位图,以便在 AlivePDF 中使用。我的测试适用于 TextArea,或者组件是否在舞台上或可见。但我希望能够处理不一定位于屏幕上的文本块。有谁知道如何做到这一点
我有一个 swing 应用程序,我需要在其中运行并打开 JavaFX 场景/阶段。我必须在没有扩展应用程序的情况下运行它。我已经尝试了 Stackoverflow 上发布的大多数解决方案,但没有一个适
我正在寻找一种方法来缩小 Flash 文件的高度。我可以更改宽度,但高度似乎与其所在窗口的大小有关? http://www.bevelite.com.au/test 我正在使用 page-flip.c
我需要在选择组合框元素时重新绘制窗口。如何在 JAVA FX 2.2 中重绘窗口(舞台)? 下面是我的代码 functionComboBox.valueProperty().addListener(n
我是一名优秀的程序员,十分优秀!