title: Rotate image 90 degrees ontouch left or right
body: <p>So I'm in a bit of a crysis. I'm creating a game and I have a square with 4 different colors on each side. Can't seem to make the square rotate 90deg on right screen touch and -90deg on left screen tap. I can get it to rotate on tap but not stay at the position. Like it to be as smooth as possible.</p>
  
  <p>The Activity:</p>
  
  <pre><code>public class GameActivity extends Activity implements OnTouchListener {
  
      @Override
      protected void onCreate(Bundle savedInstanceState) {
          super.onCreate(savedInstanceState);
          setContentView(R.layout.activity_game);
  
          // Reference to the left and right linear screens
          LinearLayout leftTap = (LinearLayout) findViewById(R.id.leftTap);
          leftTap.setOnTouchListener(this);
          LinearLayout rightTap = (LinearLayout) findViewById(R.id.rightTap);
          rightTap.setOnTouchListener(this);
      }
  
  
      @Override
      public boolean onTouch(View v, MotionEvent event) {
  
          // Square itself
          ImageView square = (ImageView) findViewById(R.id.square);
  
          // Left and Right Animations
          Animation leftAnimation = AnimationUtils.loadAnimation(this, R.anim.rotate_left_animation);
          Animation rightAnimation = AnimationUtils.loadAnimation(this, R.anim.rotate_right_animation);
  
          switch (v.getId()) {
              case R.id.leftTap:
                  // Do left Rotate animation
                  square.startAnimation(leftAnimation);
  
                  break;
  
              case R.id.rightTap:
                  // Do right Rotate animation
                  square.startAnimation(rightAnimation);
  
                  break;
  
              default:
                  break;
          }
          return false;
      }
  
  }
  </code></pre>
  
  <p>The Layout:</p>
  
  <pre><code>&lt;RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
      xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent"
      android:layout_height="match_parent"
      tools:context=".GameActivity"
      android:weightSum="1"
      android:theme="@android:style/Theme.NoTitleBar.Fullscreen"&gt;
  
      &lt;LinearLayout
          android:orientation="horizontal"
          android:layout_width="fill_parent"
          android:layout_height="fill_parent"
          android:id="@+id/leftTap"
          android:visibility="visible"
          android:layout_alignParentTop="true"
          android:layout_toLeftOf="@+id/square"&gt;&lt;/LinearLayout&gt;
  
  
      &lt;ImageView
          android:contentDescription="The Square"
          android:layout_width="100dp"
          android:layout_height="100dp"
          android:layout_centerHorizontal="true"
          android:layout_centerVertical="true"
          android:id="@+id/square"
          android:src="@drawable/photo"
          android:scaleType="fitCenter" /&gt;
  
      &lt;LinearLayout
          android:orientation="horizontal"
          android:layout_width="fill_parent"
          android:layout_height="fill_parent"
          android:id="@+id/rightTap"
          android:visibility="visible"
          android:layout_alignParentTop="true"
          android:layout_toRightOf="@+id/square"&gt;&lt;/LinearLayout&gt;
  
  
  &lt;/RelativeLayout&gt;
  </code></pre>
  
  <p>Left Tap Animation XML:</p>
  
  <pre><code>&lt;?xml version="1.0" encoding="utf-8"?&gt;
  &lt;set xmlns:android="http://schemas.android.com/apk/res/android"&gt;
      &lt;rotate
          android:duration="500"
          android:interpolator="@android:anim/linear_interpolator"
          android:pivotX="50%"
          android:pivotY="50%"
          android:toDegrees="-90"/&gt;
  &lt;/set&gt;
  </code></pre>
  
  <p>Right Tap Animation XML:</p>
  
  <pre><code>&lt;?xml version="1.0" encoding="utf-8"?&gt;
  &lt;set xmlns:android="http://schemas.android.com/apk/res/android"&gt;
      &lt;rotate
          android:duration="500"
          android:interpolator="@android:anim/linear_interpolator"
          android:pivotX="50%"
          android:pivotY="50%"
          android:toDegrees="90"/&gt;
  </code></pre>
  
  <h1>    </h1>
  
  <p>I could:</p>
  
  <pre><code>switch (v.getId()) {
  
              case R.id.leftClick:
                  square.setRotation(square.getRotation() - 90);
  
                  break;
  
              case R.id.rightClick:
                  square.setRotation(square.getRotation() + 90);
  
                  break;
  
              default:
  
                  break;
          }
  </code></pre>
  
  <p>But it won't have the animation (basically linear interpolation) affect. I want to know how can that be done?</p>