6

I have a linearlayout that contains 4 nested linear layouts. I need to hide the first nested layout and show the 2 and 3 and then hide the 2 and 3 and show the 1st. I would like to animate these transistions with sliding effects. So have the 1st slide of the screen and then the 2 and 3 slide on. I have managed to animate 1 sliding off ( although not very smoothly ) but can't figure out how to do the slide on to go from View.GONE to View.VISIBLE.

Without the animation is I just do setVisiblity on the 1st to hide it and then setVisiblity on the 2/3 to shot them then it is very glitchy and the text overlaps.

See below for the problem I am encountering.

The code that I am using to hide / show currently:

        LinearLayout item2= (LinearLayout) rootView.findViewById(R.id.item2);
        LinearLayout item1= (LinearLayout) rootView.findViewById(R.id.item2);

            item1.setVisibility(View.GONE);
            item2.setVisibility(View.VISIBLE);

enter image description here

Rishabh Srivastava
  • 3,683
  • 2
  • 30
  • 58
Nath5
  • 1,665
  • 5
  • 28
  • 46
  • You can go through the following link: http://stackoverflow.com/questions/19765938/show-and-hide-linearlayout-with-a-slide-up-down-animation – Rishabh Srivastava Apr 04 '14 at 10:32

3 Answers3

2

You can let Android animate layout changes for you. Every time you change something in the layout like changing view visibility or view positions android will automatically create fade / transition animations. To use that set this on the root node in your layout;

android:animateLayoutChanges="true"
Sabri Meviş
  • 2,231
  • 1
  • 32
  • 38
1

Use alpha animation on the view which you want to make invisible. Also use AnimationUpdateListener and once the animation is completed make the view invisible.

Miran
  • 31
  • 4
0

I think you cannot animate from VISIBLE to GONE.

I would try to animate lowering the height of your view until 0(or scaling to 0)

Also take a look here

It uses a ListView not a LinearLayout but it may suit you

Klitos G.
  • 806
  • 5
  • 14