1

I'd like to set an angle on an image view and have that angle be generated randomly, and set the ancho point of the image view to the center of the android screen. After that I'd like the computer to generate a spot from a certain distance of the middle to the end of the screen on that angle and set a button to appear there. I'm not sure if eclipse has a quick automatic way to do that.

Thanks.

I've added a picture to help. I'd like the arrow to point to a random angle and then a button to appear on that angle but outside of the circle (the circle is imaginary just showing that it needs to appear outside of a certain distance from the center.enter image description here

Liam Shalon
  • 422
  • 2
  • 5
  • 19
  • Your question is confusing - Eclipse is a development environment, are you asking for guidance on how to achieve this functionality through programming code (I see you tagged the question "java")? – ılǝ May 01 '13 at 04:26
  • Yes please. I'm looking for that specifically and I see that there is already an answer showing me how to set the rotation. I kinda got that part already. I'd like to know if I can set the anchor point (point of rotation) to something of my choice. I'd also like to set a buttons position to a random location on the screen that is on the angle set and at least a value away from the middle. (In other words I would like the button to be set to be on the angle axis but be in one quadrant and +what ever number away from the center. I'd like to do this in Eclipse (the java I thought would help). – Liam Shalon May 01 '13 at 05:00
  • Please see the link in the comment to that answer. About putting a button at a given point of the screen, after you calculate your coordinates - you can assign them to that button using setLayoutParams (plenty of examples online) – ılǝ May 01 '13 at 05:05
  • Everything looks perfect. I'd like the button though to be generated at a random point on the axis in a certain quadrant of the angle and then also 20 pxls or 20 dp away from the center. I understand everything you're saying and commenting but I want everything to be generated randomly and automatically (I should not have to plug in coordinates) but can I assign the button to appear with an X and Y value greater or larger than a certain X and Y? Not sure how I would do that. – Liam Shalon May 01 '13 at 05:23
  • You need to generate random numbers within a range? You can use the java Random class for random values between 0 and displayWidth, displayHeight. For example Random rand = new Random(); int x = rand.nextInt(displayWidth); //this can also return 0 – ılǝ May 01 '13 at 05:35
  • Added some info that may help you understand the full question. – Liam Shalon May 01 '13 at 23:13
  • let us [continue this discussion in chat](http://chat.stackoverflow.com/rooms/29275/discussion-between-ile-and-liam-shalon) – ılǝ May 02 '13 at 01:34

1 Answers1

0

You can use setRotation method for rotate a view in android.

image.setRotation(90);  // instead of 90 you can give your generated value. 
                        // But make sure the value should be float.
image.setRotationX(90); // if you want rotate depends x axis
image.setRotationY(90); // if you want rotate depends y axis

also take a look on here

I hope this will help you.

Gunaseelan
  • 14,415
  • 11
  • 80
  • 128
  • You can also use a Matrix for providing pivot X and Y as in the first answer here: http://stackoverflow.com/questions/8981845/androidrotate-image-in-imageview-by-an-angle – ılǝ May 01 '13 at 05:02
  • okay. Thank you for your comment. Its nice to know about Matrix. – Gunaseelan May 01 '13 at 07:16