user3710617
user3710617

Reputation: 29

Slide animating layout

I want to apply animation on layoutenter image description here

when i click on arrow the slide meny look like enter image description here

then clink on arrow reanimation the menuenter code here

Upvotes: 0

Views: 122

Answers (1)

AlexBalo
AlexBalo

Reputation: 1268

You can define an animation like this one that animates left to right and apply that to your layout:

<set xmlns:android="http://schemas.android.com/apk/res/android"
     android:shareInterpolator="false">
  <translate android:fromXDelta="-100%" android:toXDelta="0%"
             android:fromYDelta="0%" android:toYDelta="0%"
             android:duration="700"/>
</set>

To apply animation to a layout resource:

Animation slideInLeft;
...
slideInLeft = AnimationUtils.loadAnimation(this, R.anim.slide_in_left);
mYourLayout.startAnimation(slideInLeft);

Edit:
When the animation is finished the layout will go back to the starting position. to avoid that you can use one of these 3 approaches:

1- Define an animation listener like this and hide your layout

anim.setAnimationListener(new Animation.AnimationListener(){
    @Override
    public void onAnimationStart(Animation arg0) {
    }           
    @Override
    public void onAnimationRepeat(Animation arg0) {
    }           
    @Override
    public void onAnimationEnd(Animation arg0) {
    }
});  

2- Use a postDelayed Handler with the same duration has your animation duration and hide the layout at the end.

3- add this line to your animation:

anim.setFillAfter(true);

Hope it helps.

Upvotes: 3

Related Questions