title: FrameLayout animation don't work while changing text in a textview outside of framelayout
body: <p>I have used FrameLayout within a Gallery as the Gallery Item. There are 2 RelativeLayouts inside the FrameLayout each holding some TextView and an ImageView. There is a button outside the Gallery called 'Flip'. Clicking the button 'Flip' hides one relative layout and shows the another with flip animation. And there is also a TextView outside the Gallery in which I update some text. When the user scrolls the Gallery to select another item, then I update the TextView from Gallery's setOnItemSelected method.</p>
  
  <p>The problem is if I don't update the TextView from the setOnItemSelected method, the flipping animation works correctly. But, if I update the TextView then the animation doesn't work. Even it doesn't switch the RelativeLayout inside the FrameLayout.</p>
  
  <p>If anybody has any idea where the problem please help me.</p>
  
  <p>Here is the XML layout for the main screen:</p>
  
  <pre><code>&lt;?xml version="1.0" encoding="utf-8"?&gt;
  &lt;LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
  android:orientation="vertical"
  android:layout_width="fill_parent"
  android:layout_height="fill_parent"
  android:gravity="top|center" android:background="#0000"&gt;
  
  &lt;RelativeLayout android:id="@+id/RelativeLayout04" android:layout_height="fill_parent" android:layout_width="fill_parent"&gt;&lt;RelativeLayout android:layout_width="fill_parent" android:layout_height="wrap_content" android:background="@drawable/top_bar" android:layout_alignParentTop="true" android:id="@+id/headerRelativeLayout"&gt;&lt;Button android:id="@+id/homeButton" android:layout_height="wrap_content" android:layout_marginTop="5dip" android:background="@drawable/home_button_open" android:layout_marginLeft="5dip" android:layout_width="wrap_content" android:layout_alignParentLeft="true"&gt;&lt;/Button&gt;
  &lt;Button android:id="@+id/backButton" android:layout_height="wrap_content" android:layout_marginTop="5dip" android:background="@drawable/back_button" android:layout_toRightOf="@+id/homeButton" android:layout_width="wrap_content"&gt;&lt;/Button&gt;
  &lt;TextView android:layout_height="wrap_content" android:textSize="22sp" android:layout_toLeftOf="@+id/LinearLayout02" android:gravity="center" android:layout_toRightOf="@+id/backButton" android:id="@+id/TextView02" android:layout_width="fill_parent" android:textStyle="bold" android:layout_centerInParent="true"&gt;&lt;/TextView&gt;
  
  &lt;LinearLayout android:layout_alignParentRight="true" android:layout_width="wrap_content" android:layout_height="wrap_content" android:orientation="horizontal" android:layout_centerVertical="true" android:layout_marginRight="10dip" android:id="@+id/LinearLayout02"&gt;
  
  &lt;com.vocabAhead.SATVocab.LoginButton android:layout_marginRight="5dip" android:id="@+id/facebookButton" android:layout_width="wrap_content" android:background="@drawable/facebook_button" android:layout_height="wrap_content"&gt;&lt;/com.vocabAhead.SATVocab.LoginButton&gt;
  
  &lt;Button android:id="@+id/settingsButton" android:layout_width="wrap_content" android:background="@drawable/settings_button" android:layout_height="wrap_content" android:layout_gravity="center_vertical"&gt;&lt;/Button&gt;
  
  &lt;/LinearLayout&gt;
  &lt;/RelativeLayout&gt;
  &lt;RelativeLayout android:layout_width="fill_parent" android:layout_height="35dip" android:background="#FF212121" android:layout_alignParentBottom="true" android:id="@+id/footerRelativeLayout"&gt;
  
  &lt;Button android:id="@+id/playButton" android:layout_height="wrap_content" android:background="@drawable/play_button" android:layout_marginLeft="10dip" android:layout_width="wrap_content" android:layout_centerVertical="true" android:layout_alignParentLeft="true"&gt;&lt;/Button&gt;
  
  &lt;Button android:layout_alignParentRight="true" android:id="@+id/showScriptButton" android:layout_height="wrap_content" android:background="@drawable/infobutton" android:layout_marginRight="10dip" android:layout_width="wrap_content" android:layout_centerVertical="true"&gt;&lt;/Button&gt;
  
  &lt;TextView android:layout_height="wrap_content" android:textColor="#FFFF" android:id="@+id/itemSerialTextView" android:layout_width="wrap_content" android:layout_centerInParent="true"&gt;&lt;/TextView&gt;
  
  &lt;TextView android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_centerVertical="true" android:layout_marginLeft="5dip" android:layout_toRightOf="@+id/playButton" android:id="@+id/durationTextView" android:textColor="#FFFF"&gt;&lt;/TextView&gt;
  
  
  &lt;/RelativeLayout&gt;
  
  &lt;Gallery android:id="@+id/wordsGallery" android:layout_above="@+id/footerRelativeLayout" android:layout_below="@+id/headerRelativeLayout" android:layout_height="fill_parent" android:layout_width="fill_parent" android:scrollbars="none" android:scrollbarSize="0dip" android:layout_margin="0dip" android:gravity="fill" android:padding="0dip" android:background="#0000"&gt;&lt;/Gallery&gt;
  
  &lt;/RelativeLayout&gt;
  
  &lt;/LinearLayout&gt;
  </code></pre>
  
  <p>And here is the XML layout for the Gallery items:</p>
  
  <pre><code>&lt;?xml version="1.0" encoding="utf-8"?&gt;
  &lt;FrameLayout xmlns:android="http://schemas.android.com/apk/res/android" 
  android:id="@+id/container"
  android:layout_width="fill_parent"
  android:layout_height="fill_parent" android:layout_margin="0dip"   android:padding="0dip"&gt;
  
  &lt;RelativeLayout android:layout_height="fill_parent" android:layout_width="fill_parent" android:id="@+id/wordDetailsRelativeLayout" android:background="#FFFF"&gt;
  
  &lt;TextView android:gravity="center" android:textSize="18sp" android:layout_alignParentTop="true" android:layout_width="fill_parent" android:text="Apathy" android:textStyle="bold" android:layout_height="wrap_content" android:layout_marginBottom="5dip" android:layout_marginTop="5dip" android:id="@+id/wordTextView" android:textColor="#FF1a3f6e"&gt;&lt;/TextView&gt;
  
  &lt;TextView android:gravity="center" android:layout_width="fill_parent" android:text="verb" android:layout_height="wrap_content" android:id="@+id/partsOfSpeechTextView" android:layout_below="@+id/wordTextView" android:layout_marginBottom="5dip"&gt;&lt;/TextView&gt;
  
  &lt;LinearLayout android:paddingBottom="5dip" android:layout_width="fill_parent" android:gravity="center" android:background="#FFFF" android:id="@+id/LinearLayout01" android:layout_height="wrap_content" android:layout_alignParentBottom="true"&gt;&lt;ImageView android:src="@drawable/iphone_vocabulary_logo_15" android:id="@+id/logoImageView" android:layout_height="wrap_content" android:layout_width="wrap_content"&gt;&lt;/ImageView&gt;
  &lt;/LinearLayout&gt;
  
  &lt;LinearLayout android:layout_height="fill_parent" android:layout_marginBottom="5dip" android:layout_width="fill_parent" android:layout_below="@+id/partsOfSpeechTextView" android:orientation="vertical" android:id="@+id/imageAndMeaningLinearLayout" android:gravity="top|center_horizontal" android:layout_above="@+id/LinearLayout01"&gt;&lt;ImageView android:id="@+id/wordImageView" android:layout_height="wrap_content" android:layout_width="wrap_content"&gt;&lt;/ImageView&gt;
  
  &lt;TextView android:layout_height="wrap_content" android:id="@+id/wordMeaningTextView" android:layout_width="wrap_content" android:textColor="#F000" android:textSize="15sp" android:layout_marginLeft="10dip" android:layout_marginTop="10dip" android:layout_marginRight="10dip" android:gravity="center"&gt;&lt;/TextView&gt;
  
  &lt;/LinearLayout&gt;
  
  &lt;/RelativeLayout&gt;
  
  
  &lt;RelativeLayout android:layout_height="fill_parent" android:layout_width="fill_parent" android:background="#FFFF" android:id="@+id/wordScriptRelativeLayout" android:visibility="gone"&gt;
  &lt;TextView android:gravity="center" android:textSize="18sp" android:layout_alignParentTop="true" android:layout_width="fill_parent" android:text="Apathy" android:textStyle="bold" android:layout_height="wrap_content" android:layout_marginBottom="5dip" android:layout_marginTop="5dip" android:textColor="#FF1a3f6e" android:id="@+id/wordTextView2"&gt;&lt;/TextView&gt;
  
  &lt;TextView android:gravity="center" android:layout_width="fill_parent" android:text="verb" android:layout_height="wrap_content" android:id="@+id/partsOfSpeechTextView2" android:layout_below="@+id/wordTextView2" android:layout_marginBottom="5dip"&gt;&lt;/TextView&gt;
  
  &lt;LinearLayout android:paddingBottom="5dip" android:layout_width="fill_parent" android:gravity="center" android:background="#FFFF" android:layout_height="wrap_content" android:layout_alignParentBottom="true" android:id="@+id/LinearLayout02"&gt;&lt;ImageView android:src="@drawable/iphone_vocabulary_logo_15" android:id="@+id/logoImageView" android:layout_height="wrap_content" android:layout_width="wrap_content"&gt;&lt;/ImageView&gt;
  
  &lt;/LinearLayout&gt;
  
  &lt;LinearLayout android:layout_height="fill_parent" android:layout_width="fill_parent" android:id="@+id/wordScriptLinearLayout" android:gravity="top|center_horizontal" android:layout_below="@+id/partsOfSpeechTextView2" android:layout_above="@+id/LinearLayout02"&gt;&lt;TextView android:layout_height="wrap_content" android:layout_margin="10dip" android:id="@+id/wordScriptTextView" android:layout_width="fill_parent" android:textColor="#F000" android:textSize="15sp"&gt;&lt;/TextView&gt;
  
  &lt;/LinearLayout&gt;
  
  &lt;/RelativeLayout&gt;
  
  &lt;/FrameLayout&gt;
  </code></pre>
  
  <p>In the main screen when the user clicks the showScriptButton (right button of the footer), then framelayout's one relative layout switches with the another. The switching of the relative layout is shown with a flip animation. </p>
  
  <p>Now, there is a text view in the middle of the footer. If we change the text of that text view from code then the flip animation doesn't work even though the frame layout doesn't change the relative layouts.</p>
  
  <p>This is the setOnItemSelectedListener method for the Gallery:</p>
  
  <pre><code>wordsGallery.setOnItemSelectedListener(new OnItemSelectedListener() {
  
          @Override
          public void onItemSelected(AdapterView&lt;?&gt; arg0, View arg1,
                  int position, long arg3) {
  
              durationTextView.setText("");
  
          }
  
          @Override
          public void onNothingSelected(AdapterView&lt;?&gt; arg0) {
  
          }
      });
  </code></pre>
  
  <p>Here is the method for playButton:</p>
  
  <pre><code>private void playAudio() {
      if(isPaused) {
          myRefreshThread = new Thread(new secondCountDownRunner());
          myRefreshThread.start();
          audioPlayer.start();
      } else {
          audioPlayer = MediaPlayer.create(this, ApplicationCache.wordAudioList.get(word.wordText));
          audioPlayer.setOnCompletionListener(this);
          int totalDuration = audioPlayer.getDuration()/1000;
          String durationText = "";
            int min = totalDuration/60;
            int seconds = totalDuration % 60;
            if(min &lt; 10)
                durationText = "0";
            durationText += min+":";
            if(seconds &lt; 10)
                durationText += "0";
            durationText += seconds;
          System.out.println("Duration of audio:"+durationText);
          durationTextView.setText(durationText);
          myRefreshThread = new Thread(new secondCountDownRunner());
          myRefreshThread.start();
          audioPlayer.start();
      }
      isPaused = false;
      isPlaying = true;
      playButton.setBackgroundResource(R.drawable.pause_button);
  }
  </code></pre>
  
  <p>And here is the secondCountDownRunner thread:</p>
  
  <pre><code>class secondCountDownRunner implements Runnable{
      // @Override
      public void run() {
          while(!Thread.currentThread().isInterrupted()){
              Message m = new Message();
              m.what = 2;
              audioPlayerHandler.sendMessage(m);
              try {
                  Thread.sleep(1000);
              } catch (InterruptedException e) {
                  Thread.currentThread().interrupt();
              }
          }
      }
  }
  </code></pre>
  
  <p>and here is the audioPlayerHandler:</p>
  
  <pre><code>audioPlayerHandler = new Handler() {
          @Override
          public void handleMessage( Message msg ) 
          {
                if(msg.what == 1) {
                    if(isPlaying) {
                        if(wordsGallery.getSelectedItemPosition() &lt; (ApplicationCache.dontKnowWords.size() - 1)) {
                          //currentPosition++;
                          //currentGalleryPosition++;
                          //isWordScriptShowing = false;
                          //updateWordDetails();
                          word = wordsList.get(wordsGallery.getSelectedItemPosition() + 1);
                          wordsGallery.setSelection(wordsGallery.getSelectedItemPosition() + 1, true);
  
                          playAudio();
                        }
                    }
                } else if(msg.what == 2) {
                    if(isPlaying) {
                        int duration = audioPlayer.getDuration()/1000;
                        int currentPosition = audioPlayer.getCurrentPosition()/1000;
                        int timeLeft = duration - currentPosition;
                        if(timeLeft &lt; 0)
                            timeLeft = 0;
                        String durationText = "";
                        int min = timeLeft/60;
                        int seconds = timeLeft % 60;
                        if(min &lt; 10)
                            durationText = "0";
                        durationText += min+":";
                        if(seconds &lt; 10)
                            durationText += "0";
                        durationText += seconds;
                        durationTextView.setText(durationText);
  
                    }
                }             
          }           
      };
  </code></pre>
  
  <p>Here is the method which is called when showScriptButton is clicked:</p>
  
  <pre><code>public void flipView(int position) {
      applyRotation(0, 90, position);
      isFrontShowing[position] = !isFrontShowing[position];       
  }
  
  private void applyRotation(float start, float end, int position) {
      // Find the center of image
      final float centerX, centerY;
      if(isFrontShowing[position] == true) {
          centerX = detailsLayout[position].getMeasuredWidth() / 2.0f;
          centerY = detailsLayout[position].getMeasuredHeight() / 2.0f;
      } else {
          centerX = scriptLayout[position].getMeasuredWidth() / 2.0f;
          centerY = scriptLayout[position].getMeasuredHeight() / 2.0f;
      }
  
      //System.out.println("center X:"+centerX+",Y:"+centerY);
      // Create a new 3D rotation with the supplied parameter
      // The animation listener is used to trigger the next animation
      final Flip3dAnimation rotation =
             new Flip3dAnimation(start, end, centerX, centerY);
      rotation.setDuration(500);
      rotation.setFillAfter(true);
      rotation.setInterpolator(new AccelerateInterpolator());
      rotation.setAnimationListener(new DisplayNextView(isFrontShowing[position], detailsLayout[position], scriptLayout[position]));
  
      if (isFrontShowing[position] == true)
      {
          //detailsLayout[position].requestFocus();
          //detailsLayout[position].bringToFront();
          detailsLayout[position].startAnimation(rotation);
      } else {
          //System.out.println("---Backward flipping started...");
          //scriptLayout[position].requestFocus();
          //scriptLayout[position].bringToFront();
          scriptLayout[position].startAnimation(rotation);
      }
  
  }
  </code></pre>
  
  <p>Here is the Flip3dAnimation class:</p>
  
  <pre><code>import android.graphics.Camera;
  </code></pre>
  
  <p>import android.graphics.Matrix;
  import android.view.animation.Animation;
  import android.view.animation.Transformation;</p>
  
  <p>public class Flip3dAnimation extends Animation {
      private final float mFromDegrees;
      private final float mToDegrees;
      private final float mCenterX;
      private final float mCenterY;
      private Camera mCamera;</p>
  
  <pre><code>public Flip3dAnimation(float fromDegrees, float toDegrees, float centerX,
          float centerY) {
      mFromDegrees = fromDegrees;
      mToDegrees = toDegrees;
      mCenterX = centerX;
      mCenterY = centerY;
  }
  
  @Override
  public void initialize(int width, int height, int parentWidth,
          int parentHeight) {
      super.initialize(width, height, parentWidth, parentHeight);
      mCamera = new Camera();
  }
  
  @Override
  protected void applyTransformation(float interpolatedTime, Transformation t) {
      final float fromDegrees = mFromDegrees;
      float degrees = fromDegrees
              + ((mToDegrees - fromDegrees) * interpolatedTime);
  
      final float centerX = mCenterX;
      final float centerY = mCenterY;
      final Camera camera = mCamera;
  
      final Matrix matrix = t.getMatrix();
  
      camera.save();
  
      camera.rotateY(degrees);
  
      camera.getMatrix(matrix);
      camera.restore();
  
      matrix.preTranslate(-centerX, -centerY);
      matrix.postTranslate(centerX, centerY);
  
  }
  </code></pre>
  
  <p>}</p>
  
  <p>DisplayNextView class:</p>
  
  <pre><code>import android.view.animation.Animation;
  </code></pre>
  
  <p>import android.widget.RelativeLayout;</p>
  
  <p>public final class DisplayNextView implements Animation.AnimationListener {
      private boolean mCurrentView;
      RelativeLayout layout1;
      RelativeLayout layout2;</p>
  
  <pre><code>public DisplayNextView(boolean currentView, RelativeLayout layout1,
          RelativeLayout layout2) {
      mCurrentView = currentView;
      this.layout1 = layout1;
      this.layout2 = layout2;
  }
  
  public void onAnimationStart(Animation animation) {
  
  }
  
  public void onAnimationEnd(Animation animation) {
      layout1.post(new SwapViews(mCurrentView, layout1, layout2));        
  }
  
  public void onAnimationRepeat(Animation animation) {
  }
  </code></pre>
  
  <p>}</p>
  
  <p>SwapViews class:</p>
  
  <pre><code>import android.view.View;
  </code></pre>
  
  <p>import android.view.animation.Animation;
  import android.view.animation.DecelerateInterpolator;
  import android.view.animation.Animation.AnimationListener;
  import android.widget.RelativeLayout;</p>
  
  <p>public final class SwapViews implements Runnable {
      private boolean mIsFirstView;
      RelativeLayout layout1;
      RelativeLayout layout2;</p>
  
  <pre><code>public SwapViews(boolean isFirstView, RelativeLayout layout1, RelativeLayout layout2) {
      mIsFirstView = isFirstView;
      this.layout1 = layout1;
      this.layout2 = layout2;
  }
  
  public void run() {
      final float centerX, centerY;
      if(mIsFirstView) {
          centerX = layout1.getWidth() / 2.0f;
          centerY = layout1.getHeight() / 2.0f;
      } else {
          centerX = layout2.getWidth() / 2.0f;
          centerY = layout2.getHeight() / 2.0f;
      }
  
      Flip3dAnimation rotation;
  
      if (mIsFirstView == true) {
          layout1.setVisibility(View.GONE);
          layout2.setVisibility(View.VISIBLE);
          layout2.requestFocus();
          layout2.bringToFront();
          rotation = new Flip3dAnimation(-90, 0, centerX, centerY);
      } else {
          layout2.setVisibility(View.GONE);
          layout1.setVisibility(View.VISIBLE);
          layout1.requestFocus();
          layout1.bringToFront();
          rotation = new Flip3dAnimation(-90, 0, centerX, centerY);
      }
  
      rotation.setDuration(500);
      rotation.setFillAfter(true);
      rotation.setInterpolator(new DecelerateInterpolator());
      rotation.setAnimationListener(new AnimationListener() {
  
          @Override
          public void onAnimationStart(Animation arg0) {
  
          }
  
          @Override
          public void onAnimationRepeat(Animation arg0) {
              // TODO Auto-generated method stub
  
          }
  
          @Override
          public void onAnimationEnd(Animation arg0) {
              WordDetailItemAdapter.notifyAdapter();
          }
      });
      if (mIsFirstView == true) {
          layout2.startAnimation(rotation);
      } else {
          layout1.startAnimation(rotation);
      }
  }
  </code></pre>
  
  <p>}</p>
  
  <p>Does anyone have some idea about the problem. Please help.</p>