将Android Matrix值转换为View转换属性

时间:2014-06-24 16:21:54

标签: android matrix view transform

我有一个使用View.setRotationX和View.setRotationY围绕X轴和Y轴旋转的视图。我使用了View.getMatrix()并修改了Matrix的值。我现在想将Matrix应用回View,但是我没有找到一种很好的方法来实现这一点而不使用Android中的旧版动画API。

illustration of my view

基本上我需要的是将Matrix值转换为View转换值。 例如:

float[] src = new float[]{0, 0, view.getWidth(), 0, 0, view.getHeight(), view.getWidth(), view.getHeight()};
float[] dst = new float[8];

Matrix matrix = view.getMatrix();
matrix.mapPoints(dst, src);
dst[7] = NEW_Y_COORD_OF_CORNER;
matrix.setPolyToPoly(src, 0, dst, 0, dst.length >> 1);
//The matrix is now changed but the View is not.

So i would like to get rotation and translation of the Matrix to apply it back to the View:

float newRotationX = convertMatrixRotationToViewRotationX(matrix); //method i need
float newRotationY = convertMatrixRotationToViewRotationY(matrix); //method i need

float newTranslationX = convertMatrixRotationToViewTranslationX(matrix); //method i need
float newTranslationY = convertMatrixRotationToViewTranslationY(matrix); //method i need

view.setRotationY(newRotationX);
view.setRotationX(newRotationY);
view.setX(newTranslationX);
view.setY(newTranslationY);

这似乎是一种转换视图的复杂方法,但我需要这样做,以便能够设置视图的x,y角坐标。有关获取方式的角坐标的详细信息,请参阅我之前的帖子:https://stackoverflow.com/questions/24330073/how-to-get-all-4-corner-coordinates-of-a-view-in-android?noredirect=1#comment37672700_24330073

0 个答案:

没有答案