Skizit
Skizit

Reputation: 44862

Android: Layouts "slide" off the screen?

I've got a layout much like the one below. Currently when the back button is pressed the red linear layout's visibility is set to gone. However, I'd like it to "slide" up off of the page instead. How would I do this?

my layout

Upvotes: 10

Views: 13931

Answers (1)

DArkO
DArkO

Reputation: 16110

You need to use animations. here is the top in/out animations:

In Top

  <?xml version="1.0" encoding="utf-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android">
    <translate android:fromYDelta="-100%" android:toYDelta="0%" android:duration="300"/>
</set>

Out Top

<?xml version="1.0" encoding="utf-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android">
    <translate android:fromYDelta="0%" android:toYDelta="-100%" android:duration="600"/>
</set>

Then in your activity get the view and apply an animation to it like this: This are type Animation.

  mSlideInTop = AnimationUtils.loadAnimation(this, R.anim.slide_in_top);
        mSlideOutTop = AnimationUtils.loadAnimation(this, R.anim.slide_out_top);

and call them with this code:

header.startAnimation(mSlideOutTop);
        header.setVisibility(View.INVISIBLE);

Here header is a LinearLayout wrapping my views. same thing if you want to make it slide in. just add the slide in animation and make the view visible.

Upvotes: 36

Related Questions