【问题标题】:Center of the view after rotation or scale旋转或缩放后的视图中心
【发布时间】:2017-01-02 08:37:18
【问题描述】:

我正在尝试找到视图的中心。对于非旋转视图,该值是正确的,但对于旋转视图,它是不正确的,因为 center(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 我只得到可见部分的矩形

【问题讨论】:

  • 您真正想要实现什么?你的意思是什么缩放?
  • 没有缩放或旋转以上是正确的
  • 所以调用View#getMatrix() 并使用Matrix 映射您想要的任何点(不仅是中心点)
  • 如何从矩阵中获取中心

标签: android image-rotation


【解决方案1】:

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

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

【讨论】:

    猜你喜欢
    • 2021-05-08
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-02-27
    相关资源
    最近更新 更多