0

Goal:
Get the width, height, and margins from a rotated view.
I'm rotating the view with: view.animate().rotationBy(90);
I've also tried doing it with a RotateAnimation to no avail.

Details:
I'm moving a non-square view around the screen, with the ability to rotate it, and I want to keep the view within the bounds of the screen - e.g. no part of the view leaves the screen. Or at least if it does, it moves back in bounds.

When the view isn't rotated, everything works fine when I use LayoutParams and prevent its top and left margins from being negative (or greater than the height/width of the screen, respectively). I'm running into problems when the view is rotated because when I use the LayoutParams, they're retaining their values from the non-rotated View.

Example:
See screenshot of Excel-built example. If my original view's top-left corner is one cell each from the top and left (1,1), when rotated 90 degrees, I'd expect the new top-left corner to be two cells from the top, and zero cells from the left (2,0). However, the top-left corner (as far as the LayoutParams are concerned), remains at 1,1.

Within the same example, the height and width do not change in the LayoutParams. Whether or not it's rotated, the height is always four cells and the width is always two.

screenshot of Excel-built example

Phantômaxx
  • 37,901
  • 21
  • 84
  • 115
mikemass90
  • 11
  • 1
  • 3
  • This may help: https://stackoverflow.com/questions/21355784/android-rotate-whole-layout – acarlstein May 20 '19 at 16:18
  • Didn't work. Width and height from LayoutParams remain unchanged and it actually cuts off part of the view. – mikemass90 May 21 '19 at 03:37
  • Perhaps, you should add some code, of what you are trying to do, into your question. It will increase the chances of getting an answer that way. – acarlstein May 21 '19 at 12:56

0 Answers0