TranslateAnimation after reposition of view does not work properly
<p>I am trying to create a page indicator like a horizontal scroll bar, so when i flip  the screen, the scroll bar will move to the new position with animation. For some reason, i want to keep the new position of the scroll bar. here's my code:</p>

<p>main.xml </p>

<pre><code>&lt;RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"&gt;

    &lt;com.scroll.PageIndicator
        android:id="@+id/indicator"
        android:layout_width="80dip"
        android:layout_height="8dip"
        android:layout_alignParentBottom="true"
        android:layout_centerHorizontal="true"
        android:layout_centerVertical="true"
        android:layout_marginBottom="15dip" &gt;

&lt;/com.scroll.PageIndicator&gt;
</code></pre>

<p></p>

<p>indicator_content.xml:</p>

<pre><code>&lt;FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent" &gt;

&lt;View
    android:id="@+id/indicator_container"
    style="@style/editview_style"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:background="@drawable/horizontal_bar_nor"&gt;
&lt;/View&gt;

&lt;View
    android:id="@+id/indicator_faded_scroll_bar"
    android:layout_width="40dip"
    android:layout_height="fill_parent"
    android:layout_gravity="left"
    android:background="@drawable/horizontal_bar_pre"/&gt;
&lt;/FrameLayout&gt;
</code></pre>

<p>below is the code for animation, PageIndicator.java:</p>

<pre><code>public class PageIndicator extends LinearLayout{
    private LayoutInflater mInflater;
    private View mScrollBar;
    private FrameLayout mLayout;
    private Animation fadeAnimation;

public PageIndicator(Context context, AttributeSet attrs) {
    super(context, attrs);

    this.context = context;
    initPaints();
}

public PageIndicator(Context context) {
    super(context);

    this.context = context;
    initPaints();
}

private final void initPaints() {
    setOrientation(LinearLayout.HORIZONTAL);

    mInflater = (LayoutInflater)     context. getSystemService   (Context.LAYOUT_INFLATER_SERVICE); 
    mLayout = (FrameLayout) mInflater.inflate(R.layout.indicator, this, false);
    mScrollBar = (View) mLayout.findViewById(R.id.indicator_faded_scroll_bar_left);       
    mScrollBar.setVisibility(View.INVISIBLE);  
    addView(mLayout);
    mLeft = mScrollBar.getLeft();
 }

public void switchScrollBar(int whichScreen) {
    mScrollBar.clearAnimation();
    mDistance = getWidth() / 2;
    mWhichScreen = whichScreen;
    newTop = mScrollBar.getTop();

    if (mWhichScreen == 0) {
        TranslateAnimation moveRighttoLeft = new TranslateAnimation(mDistance, 0, 0, 0);
        moveRighttoLeft.setDuration(200);
        moveRighttoLeft.setFillEnabled(true);
        moveRighttoLeft.setFillAfter(true);
        moveRighttoLeft.setAnimationListener(new DetectViewChangedListener());
        mState = SCROLLTOLEFT;
        mScrollBar.startAnimation(moveRighttoLeft);
        mScrollBar.invalidate();

    } else {

        TranslateAnimation moveLefttoRight = new TranslateAnimation(0, mDistance, 0, 0);
        moveLefttoRight.setDuration(200);
        moveLefttoRight.setFillEnabled(true);
        moveLefttoRight.setFillAfter(true);

        moveLefttoRight.setAnimationListener(new DetectViewChangedListener());
        mState = SCROLLTORIGHT;
        mScrollBar.startAnimation(moveLefttoRight);
        mScrollBar.invalidate();

    }
}

private final class DetectViewChangedListener implements Animation.AnimationListener {

    public void onAnimationEnd(Animation animation) {
        switch (mState) {
            case SCROLLTOLEFT:
                mState = REST;
                 mScrollBar.layout(0, newTop, 0+mScrollBar.getWidth(), newTop
                         + mScrollBar.getHeight());
                invalidate();
                break;
            case SCROLLTORIGHT:
                mState = REST;
                mScrollBar.layout(mDistance, newTop, mDistance + mScrollBar.getWidth(), newTop + mScrollBar.getHeight());
                invalidate();
                break;

            default:
                invalidate();
                break;
        }

    }

}
</code></pre>

<p>OK, switchScrollBar() method is for the animation work. when the scrollbar is moved to right and position there, animation works perfectly, harahh~ but when i start to scroll to left from the new position, the TranslateAnimation works really wired. i have tested many times and it seems like the layout() method is not working properly. this is really annoying, hope someone knows the reason, any help would be appreciated.</p>
