gpt4 book ai didi

android - 旋转或缩放后的 View 中心

转载 作者:行者123 更新时间:2023-12-04 17:54:37 26 4
gpt4 key购买 nike

我正在尝试找到 View 的中心。对于非旋转 View ,该值是正确的,但对于旋转 View ,它不正确,因为中心 (0,0) 正在旋转。在缩放的情况下,即使缩放后宽度和高度也保持不变

我正在使用以下公式计算中心。

 int[] location = new int[2];
childView.getLocationOnScreen(location);
int xLocation = location[0] + childView.getWidth() / 2;
int yLocation = location[1] + childView.getHeight() / 2

getGlobalVisibleRect 我只得到可见部分的矩形

最佳答案

https://developer.android.com/reference/android/view/View#getHitRect(android.graphics.Rect)

此方法将在其父 View 中返回 Rect(考虑旋转和缩放)

关于android - 旋转或缩放后的 View 中心,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41423569/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com