【发布时间】:2018-09-25 17:46:59
【问题描述】:
首先,让我道歉,但我不知道还能问哪里。
想看懂下面的代码可以found here.
除了getViewTreeObserver 位之外,我都了解:
movingView.getViewTreeObserver().addOnGlobalLayoutListener(new ViewTreeObserver.OnGlobalLayoutListener() {
@Override
public void onGlobalLayout() {
yAnimation = createSpringAnimation(movingView,SpringAnimation.Y, movingView.getY(), STIFFNESS, DAMPING_RATIO);
xAnimation = createSpringAnimation(movingView,SpringAnimation.X, movingView.getX(), STIFFNESS, DAMPING_RATIO);
movingView.getViewTreeObserver().removeOnGlobalLayoutListener(this);
}
});
为什么我们需要这个位?最后一行,从movingView 中删除了OnGlobalLayoutListener,所以我不明白为什么我们设置它然后删除它。如果我从这个监听器中取出yAnimation 和xAmination 行,然后自己运行它们,代码仍然可以正常工作,但是它不会返回到原来的X 和Y。但我不明白为什么上面代码允许createSpringAnimation函数接收正确的 X 和 Y。
拜托,谁能帮我理解一下?
【问题讨论】: