title: How to rotate a view from two different angles?
body: <p>I am trying to rotate an ImageButton by 180 degrees so it matches the reverse portrait orientation. When I did this the same way as the other orientation changes, the result was perfect, but not the animation.</p>
  
  <pre><code> public void onOrientationChanged(int DeviceAngle) {
        float MyButtonCurrentAngle = MyButton.getRotation(); //Gets portrait rotation (0)
             if(DeviceAngle &gt; 350 || DeviceAngle &lt; 10) { //Portrait
                  MyButton.animate().rotationBy(- MyButtonCurrentAngle).setDuration(100).start();
             } else if(DeviceAngle &gt; 80 &amp;&amp; DeviceAngle &lt; 100) { //Reverse Landscape
                  MyButton.animate().rotationBy(-90 - MyButtonCurrentAngle ).setDuration(100).start();
              } else if(DeviceAngle &gt; 170 &amp;&amp; DeviceAngle &lt; 190) { //Reverse Portrait
                  MyButton.animate().rotationBy(180 -  MyButtonCurrentAngle).setDuration(100).start();
             } else if(DeviceAngle &gt; 260 &amp;&amp; DeviceAngle &lt; 280) { //Landscape
                  MyButton.animate().rotationBy(90 - MyButtonCurrentAngle ).setDuration(100).start();
             }          
  </code></pre>
  
  <p>I thought this happens, because the float MyButtonCurrentAngle gets MyButton rotation angle value (0 or not rotated) from the DeviceAngle between 350 and 10 (0 or 360, Portrait orientation) and uses it as a reference.</p>
  
  <p>Even though I'm still doubting, I discarded the previous case. The float seemed to work well with the other orientations and I think the problem is the animation for the Reverse Portrait orientation. The button shouldn't be rotated by 180, but by either 90 or -90 degrees. This is because you can't rotate a device from Portrait to Reverse Portrait without going through either landscape option. (Can't rotate Portrait to Reverse Portrait directly).</p>
  
  <p>After many unsuccessful attempts, I came to the conclusion that I can't use MyButton gotten angle value, after the button has been rotated and the orientation detected is either Landscape or Reverse Landscape. I thought about the creation of another float to get the Reverse Portrait MyButton angle value, but this activity's orientation is set to Portrait, so this doesn't make sense.</p>
  
  <p>Therefore, I need to get MyButton rotation angle after it's been rotated with a float, using this values as a loop condition, and depending on the result, rotate it by 90 degrees or -90 degrees in two different animations. This was my latest approach to the issue:</p>
  
  <pre><code>    while (MyButtonCurrentAngle==90) { 
      if (DeviceAngle &gt; 170 &amp;&amp; DeviceAngle &lt; 190) {
          MyButton.animate().rotationBy(90 - MyButtonCurrentAngle).setDuration(100).start();
      }
  }
  while (MyButtonCurrentAngle==270) { 
      if (DeviceAngle &gt; 170 &amp;&amp; DeviceAngle &lt; 190) {
          MyButton.animate().rotationBy(-90 - MyButtonCurrentAngle).setDuration(100).start();
      }
  }
  </code></pre>
  
  <p>Basically, this handles the device orientation from landscape and reverse landscape to reverse portrait. This didn't trigger any animation, so MyButtonCurrentAngle float angle value never changed or couldn't be detected? Why can't the if statements read it? I don't know and I would like to know what I am doing wrong. Thanks in advance.</p>