ANDROID JAVA move control in direction in degrees

你。 提交于 2019-12-13 19:12:05

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!