Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

like image 912
Skizit Avatar asked Jun 13 '11 11:06

Skizit


1 Answers

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.

like image 97
DArkO Avatar answered Oct 14 '22 18:10

DArkO