我正在尝试使用 ObjectAnimator.ofFloat(...) 将视图移动到屏幕的右上角但是,我没有得到我期望的结果。我使用 ViewTreeListener 等预先获取了视图的坐标,并且我已经知道需要从整体宽度的末端偏移的 x 值。我无法让任何一个维度移动到我想要的位置。相关代码:
获取起始坐标;当前视图在哪里:
int[] userCoords = new int[]{0,0};
userControlLayout.getLocationInWindow(userCoords);
//also tried getLocationInScreen(userCoords); same result
userUpLeft = userCoords[0];
userUpTop = userCoords[1];
令人惊讶的是,当我打电话时,我得到的值与 userUpLeft 相同(在屏幕坐标中,而不是相对于父级),userControlLayout.getLeft()
根据我对文档的理解,我希望它们会有所不同。反正...
构造 ObjectAnimator:
//testXTranslate is a magic number of 390 that works; arrived at by trial. no idea why that
// value puts the view where I want it; can't find any correlation between the dimension
// and measurements I've got
ObjectAnimator translateX = ObjectAnimator.ofFloat(userControlLayout, "translationX",
testXTranslate);
//again, using another magic number of -410f puts me at the Y I want, but again, no idea //why; currently trying the two argument call, which I understand is from...to
//if userUpTop was derived using screen coordinates, then isn't it logical to assume that -//userUpTop would result in moving to Y 0, which is what I want? Doesn't happen
ObjectAnimator translateY = ObjectAnimator.ofFloat(userControlLayout, "translationY",
userUpTop, -(userUpTop));
我的理解是,一个 arg 调用相当于指定要翻译/移动到的结束坐标,并且两个 arg 版本开始于...结束于,或者,从...到我搞砸了两者都无法到达那里。
显然,我缺少非常基础的知识,只是想弄清楚那到底是什么。非常感谢任何指导。谢谢。