1

I want to create animation with two actions. First action: view go forward, second action: view go back. I create xml for describe animation, but it doesn't work. Thank you for your attention. My /anim/move_animation.xml:

 <?xml version="1.0" encoding="utf-8"?>
    <set xmlns:android="http://schemas.android.com/apk/res/android"
                android:interpolator="@android:anim/linear_interpolator">
          <translate
           android:fromYDelta="50%" 
           android:toYDelta="50%"
           android:fromXDelta="0%" 
           android:toXDelta="50%"
           android:duration="2000" />
        <translate
           android:startOffset="2000"
           android:fromYDelta="50%" 
           android:toYDelta="50%"
           android:fromXDelta="50%" 
           android:toXDelta="0%"
           android:duration="2000" />
    </set>

Activity:

public class TestActivity extends Activity {
    private LinearLayout LL;
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);

        LL = (LinearLayout) this.findViewById(R.id.MainLayout);

        Animation anim = AnimationUtils.loadAnimation(this, R.anim.move_animation);
        LL.startAnimation(anim);
    }
}

Layout:

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:orientation="vertical"
    android:id="@+id/MainLayout" >
     <ImageView
          android:id="@+id/Icon"
          android:layout_width="30dp"
          android:layout_height="30dp"
          android:background="@drawable/icon" >
      </ImageView>
</LinearLayout>
PihPah
  • 11
  • 2
  • what doesn't work about it. You're probably going to need to elaborate more if you expect us to be able to help. – FoamyGuy Mar 13 '12 at 20:31
  • do two different animations, run them after each other, if still your problem occurs, it means there is problem with the way you doing the animation. – Hesham Saeed Mar 13 '12 at 20:34
  • @Tim Thank you for your comment. I special create test small project for resolve this problem. I added other files to the topic. – PihPah Mar 13 '12 at 22:23
  • @HeshamSaeed yes, i except that view move forward and than go back, but at first time i view is invisible and after 4 or 6 secons view will show at start position(0,0). – PihPah Mar 13 '12 at 22:26
  • Please elaborate more, of what you are getting and what you really want to do, specific explanation (what do you mean by go forward? You want to move the image or the whole layout?) – Hesham Saeed Mar 13 '12 at 22:46
  • Are you trying to animate a whole activity? Something like this: http://blog.blundell-apps.com/animate-an-activity/ – Blundell Mar 13 '12 at 23:31
  • I think the answer to this: http://stackoverflow.com/questions/4482261/how-to-run-translate-animation-sequentially will help you. – dumbfingers Oct 09 '12 at 10:59

1 Answers1

0

make 2 animations of you animation. first will be first translate and second animation will be your second translate. and you setonanimationlistener and onanimationend in it. when first will end you nned to start second. it will work nice

Sergey Sheleg
  • 720
  • 6
  • 6