Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Animate Resize View in Material Design

Without involving layoutParams, is there another way to resize, collapse or expand a view? I saw that animations in some vieos of the new Material Design and in the new Android Dialer App. Google said Material can change shape, size, rotation, color, etc. easyly ... but I can't find anything.

Is there backwards compatibility?

Until now in order to resize, collapse or expand a view we had to work with layoutParams like this for example:

public static void collapse(final View v) {
final int initialHeight = v.getMeasuredHeight();

Animation a = new Animation()
{
    @Override
    protected void applyTransformation(float interpolatedTime, Transformation t) {
        if(interpolatedTime == 1){
            v.setVisibility(View.GONE);
        }else{
            v.getLayoutParams().height = initialHeight - (int)(initialHeight * interpolatedTime);
            v.requestLayout();
        }
    }

    @Override
    public boolean willChangeBounds() {
        return true;
    }
};

a.setDuration((int)(initialHeight / v.getContext().getResources().getDisplayMetrics().density));
v.startAnimation(a);

}

Here is an example of what I want from the new Google Android Dialer App:

enter image description here

like image 381
stanete Avatar asked Nov 07 '14 09:11

stanete


People also ask

How do I change an animation layout?

All you need to do is set an attribute in the layout to tell the Android system to animate these layout changes, and system-default animations are carried out for you. Tip: If you want to supply custom layout animations, create a LayoutTransition object and supply it to the layout with the setLayoutTransition() method.

How do you animate a fragment?

To animate the transition between fragments, or to animate the process of showing or hiding a fragment you use the Fragment Manager to create a Fragment Transaction . Within each Fragment Transaction you can specify in and out animations that will be used for show and hide respectively (or both when replace is used).

What is transition animation in Android?

Android's transition framework allows you to animate all kinds of motion in your UI by simply providing the starting layout and the ending layout.


1 Answers

I think ViewPropertyAnimator is what you want. check this link http://developer.android.com/guide/topics/graphics/prop-animation.html#view-prop-animator

Here is an example:

view.animate().scaleY(endHeight/initialHeight).start()

this is the same animation that you did in your code

like image 167
user3285324 Avatar answered Oct 17 '22 03:10

user3285324