I want to make a game which requires several objects to rotate around the center of the screen when you press a button ( go left or right ), however they need to orbit the center periodically as you press the button, not move when you press it once. I can make them move in that way but they do a 360 spin or go back to their original position. Can someone give me an example of how to do this? Its the same functionality as in the circle pong app. Thank you!
Asked
Active
Viewed 1,975 times
0
-
you simply have to read this http://stackoverflow.com/questions/1930963/rotating-a-view-in-android – Zar E Ahmer Aug 03 '16 at 05:21
-
it needs to orbit the center of the screen as you press the button, not rotate on one clic, ill edit the question for better understanding, thank you for your answer. – Mario Landa Aug 03 '16 at 18:32
-
See this https://github.com/VadimDev/android-seekbar-like-ipod-clickwheel – Zar E Ahmer Aug 04 '16 at 06:42
-
And I have also created a knob like that http://stackoverflow.com/q/27700637/3496570 – Zar E Ahmer Aug 04 '16 at 06:43
-
That seems like what I need, thank you so much! – Mario Landa Aug 05 '16 at 21:07
-
So Mario Landa I have also given Answer down there . If this is what you need . so Accept my Answer down there – Zar E Ahmer Aug 06 '16 at 08:48
3 Answers
1
In your anim folder create an xml
<?xml version="1.0" encoding="UTF-8"?>
<rotate
xmlns:android="http://schemas.android.com/apk/res/android"
android:fromDegrees="0"
android:toDegrees="360"
android:pivotX="50%"
android:pivotY="50%"
android:repeatCount="infinite"
android:duration="1200" />
in your code
view.startAnimation(
AnimationUtils.loadAnimation(activity, R.anim.rotate_indefinitely) );

SaravInfern
- 3,338
- 1
- 20
- 44
1
There are multiple
ways to do this. If you want to do it using your own Custom View
. In computer graphics coordinate system (0,0) start from left top
corner. For that first translate
your view to center.
canvas.translate(getWidth()/2,getHeight()/2);
then in order to move an object you have to use a mathematical formula.
x = R * cos@
y = R * sin@ where range of cos and sin is between 1 and -1.
R is radius . you can simply draw your view to x,y
location . So it will display as it is moving.
and there are other simpler ways. See here
And also see a Custom knob I created at Here

Community
- 1
- 1

Zar E Ahmer
- 33,936
- 20
- 234
- 300
0
Maybe this post will help you Move ImageView elliptically around a center in a RelativeView
Here instead of 200,400 put your own diameter based on which you want to rotate the objects