1
Animation animation = new Animation() {
        @Override
        protected void applyTransformation(float interpolatedTime, Transformation t) {
            ViewGroup.LayoutParams params = slidingPane.getLayoutParams();
            int calculatedHeight = expandedHeight - ((int) (expandedHeight * interpolatedTime));
            if (calculatedHeight <= collapsedHeight) {
                calculatedHeight = collapsedHeight;
            }
            params.height = calculatedHeight;
            slidingPane.setLayoutParams(params);
            slidingPane.requestLayout();
        }

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

    };
    animation.setDuration(ANIMATION_DURATION);
    animation.setAnimationListener(animationListener);
    slidingPane.startAnimation(animation);

SlidingPane is a LinearLayout and it has a ListView as a child. ListView contains images in every row.
Now this code is working absolutely fine, but animation is not smooth. If I remove images from listview then it works fine.
I have already tried following things based on the answers on SO on similar questions -

1. Hide the content of sliding pane before animation and then again make them visible on animation end. It helps but behavior looks very odd
2. Set android:animateLayoutChanges="true" in xml, but its not animating anything



Is there anyway to solve this problem?

USER_NAME
  • 1,029
  • 1
  • 14
  • 33

1 Answers1

0

Instead of manually changing the height on each animation step, you should try to use the more systematic animation, like ValueAnimator, or ObjectAnimator:

slidingPane.animate().scaleY(0f).setInterpolator(new AccelerateDecelerateInterpolator()).setDuration(ANIMATION_DURATION);

You can use pivotY/pivotY on the view to control the anchor point of the scale animation.

Related docs: https://developer.android.com/reference/android/animation/ValueAnimator.html https://developer.android.com/reference/android/animation/ObjectAnimator.html https://developer.android.com/guide/topics/graphics/prop-animation.html

marmor
  • 27,641
  • 11
  • 107
  • 150
  • 1
    This will scale the layout, will not change the height, It is resulting in stretching the visible part of slider – USER_NAME Jun 06 '16 at 14:29
  • how you want it to animate instead of stretching? showing more / less items in the contained list, without changing their size? – marmor Jun 06 '16 at 15:02
  • It should work same like NavigationDrawer works, just from bottom to up – USER_NAME Jun 06 '16 at 15:09
  • If i'm not mistaken, NavigationDrawer animation doesn't change its height, but it slides it (translationY), if that's ok, try: slidingPane.animate().translateY(0f) – marmor Jun 07 '16 at 06:57