0
也许我想问一些明显的问题,但我找不到解决方案,所以我有一个imageview至极是一个弩,我希望它射击到我在屏幕上触摸的地方,我使用postRotate根据触摸位置的功能旋转它,问题是每次触摸它都会将新角度添加到旧的角度,依此类推。有一种方法可以获得ImageView的实际角度?获取实际角度postrotate
int scrWidth = getWindowManager().getDefaultDisplay().getWidth();
int scrHeight = getWindowManager().getDefaultDisplay().getHeight();
float x=event.getX();//capturamos x e y
float y=event.getY();
float i=0;
if(y<(scrHeight/2)){
float yf=(scrHeight/2)-y;//obtenemos la y respecto a la mitad de la pantalla
double alfa=Math.toDegrees(Math.atan2(yf, x));//encontramos el angulo para las x e y encontradas
float beta= (float) alfa; //convertimos a float para rotar
beta=beta+i;
matrix.postRotate(-beta, ballesta.getWidth()/2,ballesta.getHeight()/2); //primer valor angulo, segundo y tercero punto de ancla de la imagen
ballesta.setImageMatrix(matrix);
}
if(y>(scrHeight/2)){
float yf=y-(scrHeight/2);//obtenemos la y respecto a la mitad de la pantalla
double alfa=Math.toDegrees(Math.atan2(yf, x));//encontramos el angulo para las x e y encontradas
float beta= (float) alfa; //convertimos a float para rotar
beta=beta+i;
matrix.postRotate(beta, ballesta.getWidth()/2,ballesta.getHeight()/2);
ballesta.setImageMatrix(matrix);
}