Java 如何从anchorpane获取Anchor属性以进行绑定或动画?

Java 如何从anchorpane获取Anchor属性以进行绑定或动画?,java,javafx,properties,Java,Javafx,Properties,我试图让anchorpane leftAnchorProperty使用 aPane.leftAnchorProperty(child); 但它不起作用。谁能帮帮我吗 我的代码 Animation a = new Timeline( new KeyFrame( Duration.seconds(2), new KeyValue(MyAPane.leftAnchorProperty(child), 10) )); 没有这样的属性,因为该值存储在properties ObservableMap中。

我试图让anchorpane leftAnchorProperty使用

aPane.leftAnchorProperty(child);
但它不起作用。谁能帮帮我吗

我的代码

Animation a = new Timeline( new KeyFrame(
Duration.seconds(2), new KeyValue(MyAPane.leftAnchorProperty(child), 10)
));

没有这样的属性,因为该值存储在properties ObservableMap中。该值存储在那里,因为只有AnchorPane的子节点需要它,但节点可以添加到其他布局中

但是,在您的情况下,您只需要一个WritableValue,您可以自己轻松实现它:

WritableValue<Double> writable = new WritableValue<Double>() {

    @Override
    public Double getValue() {
        return AnchorPane.getLeftAnchor(child);
    }

    @Override
    public void setValue(Double value) {
        AnchorPane.setLeftAnchor(child, value);
    }

};

// a starting value for the animation is important, since otherwise interpolation won't work
AnchorPane.setLeftAnchor(child, 0d);

不过,请考虑使用translateX属性。这会更简单…

你能分享更多的代码,让我们看看你是如何使用它的吗?当然,我正在做一些编辑。我想你想知道你的节点在布局锚网中的位置吗?如果是这种情况,请关注布局属性layoutx/y或节点本身的局部边界,而不是容器的边界!这与setLayoutX,Y方法无关。这是关于anchorpane约束的。有人能告诉我如何使用getProperties methodinherits from node将anchorpane约束作为双属性获取吗?你介意我让你提供更多关于可写值的信息吗,它们比SimplexxxProperties等慢吗?这里使用的只是一个接口。。。如果由属性本身实现,它通常包含获取或设置属性的方法:但是,这是在不使用AnchorPane的私有成员(如映射中的值键)的情况下执行此操作的唯一方法。对于已知属性,性能如何?当然性能较差,因为它存储在映射中,因此需要查找,而不是简单地写入属性对象的字段。不过,不必对此进行优化,因为每帧只应执行一次。。。如果您想获得更好的性能,请将child的managed属性设置为false,并按照AnchorPane的方式修改layoutX、layoutY、width和height……您真是太棒了。非常感谢。