Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Umano Android SlidingUpPanel - animation

I am using the following project: https://github.com/umano/AndroidSlidingUpPanel

It works very nicely so far, but I have one issue: I want to hide the slidable panel until I press a button, then the panel should be faded in, with an animation; currently the panel is shown when the button is pressed, but without an animation, and I don't know how to implement said animation.

Any ideas would be very much welcome!

like image 300
deimos1988 Avatar asked Mar 24 '14 17:03

deimos1988


1 Answers

I know it's been 4 months since you asked, but I decided to post an answer anyways (so someone else can maybe benefit from it).

Fading in the slideable panel is relatively easy. You just need to start an AlphaAnimation on layout that represents the slideable panel. You will probably need to disable the panel shadow by adding

sothree:shadowHeight="0dp"

to the major layout in your xml.

The more interesting thing is when you want to expand the slideable panel from the bottom of the screen (if panel is anchored at the bottom). In this case, you can use the following code:

import android.view.animation.Animation;
import android.view.animation.Transformation;

import com.sothree.slidinguppanel.SlidingUpPanelLayout;

public class SlidingUpPanelResizeAnimation extends Animation {

    private SlidingUpPanelLayout mLayout;

    private float mTo;
    private float mFrom = 0;

    public SlidingUpPanelResizeAnimation(SlidingUpPanelLayout layout, float to, int duration) {
        mLayout = layout;
        mTo = to;

        setDuration(duration);
    }

    @Override
    protected void applyTransformation(float interpolatedTime, Transformation t) {
        float dimension = (mTo - mFrom) * interpolatedTime + mFrom;

        mLayout.setPanelHeight((int) dimension);

        mLayout.requestLayout();
    }
}

And start the animation by:

SlidingUpPanelLayout slidingUpPanelLayout = (SlidingUpPanelLayout) findViewById(R.id.id_of_your_major_layout);

int slideablePanelHeight = 100;
int animationDuration = 800;

SlidingUpPanelResizeAnimation animation = new SlidingUpPanelResizeAnimation(slidingUpPanelLayout, slideablePanelHeight, animationDuration);
mSlidingLayout.startAnimation(animation);
like image 147
Bartek Lipinski Avatar answered Oct 01 '22 00:10

Bartek Lipinski