0

I have an animation that moves a TextView from left to right when button is pressed. Now I want the endpoint become the new origin of next animation. Problem is that when i click button again, animation is reset and start from previous old startpoint.

 anim1=new   TranslateAnimation(Animation.RELATIVE_TO_SELF,0.0f,Animation.RELATIVE_TO_SELF,0.5f,Animation.RELATIVE_TO_SELF,0.0f,
    Animation.RELATIVE_TO_SELF,0.0f);
    anim1.setFillEnabled(true);
    anim1.setFillAfter(true);
    anim1.setInterpolator(new AnticipateInterpolator(2.5f));
    anim1.setDuration(500);

btnStart.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {
            textview1.startAnimation(anim1);
        }
    });

And this is my xml layout:

<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"
android:paddingBottom="@dimen/activity_vertical_margin"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
tools:context=".MainAnimation" >

<TextView
    android:id="@+id/textView1"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_alignParentTop="true"
    android:layout_centerHorizontal="true"
    android:layout_marginTop="20dp"
    android:text="Large Text"
    android:textAppearance="?android:attr/textAppearanceLarge" />

  <Button
    android:id="@+id/btnStart"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_alignLeft="@+id/textView1"
    android:layout_alignRight="@+id/textView1"
    android:layout_marginTop="22dp"
    android:text="Start" />
</RelativeLayout>

An help is apprecciate. Thanks a lot.

Augusto Picciani
  • 788
  • 2
  • 11
  • 31
  • You can use an animation set to queue animations. http://stackoverflow.com/questions/6267473/how-to-chain-animation-in-android-to-the-same-view – Decoy Mar 08 '14 at 16:08

1 Answers1

0

You should have two animations for this purpose one to move it from left to right and i guest another one to move the text from right to left if i understood well what you meant here.Also use a boolean to check the status for your animation in order to trigger to correct one.

example if first animation is trigger set BooleanFirstAnm =true; so next time the boutton is pressed check the BooleanFirstAnm if its true, start second anim then set BooleanFirstAnm = false;

if(BooleanFirstAnm){
BooleanFirstAnm= false;
//Start second anim
}else{
BooleanFirstAnm =true;
//start first

}

hope it help.

murielK
  • 1,000
  • 1
  • 10
  • 21