0
 <ViewFlipper
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:measureAllChildren="false">

    <RelativeLayout
        android:layout_width="match_parent"
        android:layout_height="100dp"/>
    </RelativeLayout>

    <RelativeLayout
        android:layout_width="match_parent"
        android:layout_height="200dp">
    </RelativeLayout>

</ViewFlipper>

I have view flipper. And animation with changing that views working fine:

Animation slideDown = AnimationUtils.loadAnimation(getActivity(), android.R.anim.slide_in_left);
slideDown.setDuration(900);
Animation slideUp = AnimationUtils.loadAnimation(getActivity(), android.R.anim.slide_out_right);
slideUp.setDuration(300);

mReceiverFlipper.setInAnimation(slideDown);
mReceiverFlipper.setOutAnimation(slideUp);

My problem is I can't animate my flipperView vertically. Since two child views have different height. And when I am flipping between childViews my fipperView resizing his height without animation.

So, how can I animate flipperView when his size is changing?

Phantômaxx
  • 37,901
  • 21
  • 84
  • 115
sj_8
  • 173
  • 1
  • 16
  • Instead of putting direct child(RelativeLayout) with fix height into ViewFlipper take one more parent layout for each child. – Haresh Chhelana Oct 24 '17 at 05:34
  • @HareshChhelana how it will solve the problem? If I wrap my relativeLayout with another one what is going to change? – sj_8 Oct 24 '17 at 05:41

1 Answers1

0

You can use the android:animateLayoutChanges attribute.

Add the attribute android:animateLayoutChanges on the ViewFlipper and set it to true. (<ViewFlipper android:animateLayoutChanges="true" ...)

Then in your code, you need to add this line to enable the animation:

((ViewFlipper) findViewById(/* your viewflipper id here*/)).getLayoutTransition().enableTransitionType(LayoutTransition.CHANGING)

or in Kotlin:

findViewById<ViewFlipper>(/* your viewflipper id here*/).layoutTransition.enableTransitionType(LayoutTransition.CHANGING)

Source: https://proandroiddev.com/the-little-secret-of-android-animatelayoutchanges-e4caab2fddec

LCZ
  • 589
  • 1
  • 9
  • 15