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:
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.
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).
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.
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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With