问题
How do you move an control (for example a ImageView) in a certain direcion in degrees. There is no coordinate where the control needs to stop moving. we want to move it in a direction in degrees (0-360)
This doesn't work:
RelativeLayout.LayoutParams params = new RelativeLayout.LayoutParams(RelativeLayout.LayoutParams.WRAP_CONTENT, RelativeLayout.LayoutParams.WRAP_CONTENT);
params.setMargins(100,75, 0,0);
params.topMargin= 100;
回答1:
Found the solution, this is it: Sinus was the solution...
RelativeLayout root = (RelativeLayout) findViewById( R.id.rootLayout );
int originalPos[] = new int[2];
bal.getLocationOnScreen( originalPos );
Double sin = (Math.sin(Math.toRadians(degrees)) * (root.getHeight() / 2 )) / Math.sin(Math.toRadians(90 - degrees));
来源:https://stackoverflow.com/questions/29343400/android-java-move-control-in-direction-in-degrees