Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Smoothly animate view hide / show in linear layout android

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

like image 828
Nath5 Avatar asked Nov 23 '13 02:11

Nath5


People also ask

What is the difference between VIEW gone and view invisible?

A View's visibility status is of Integer type and can have one of three options: VISIBLE (0) - The View is visible to the user. INVISIBLE (4) - The View is invisible to the user, but still takes up space in the layout. GONE (8) - The View is invisible, and it does not take up space in the layout.


2 Answers

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.

like image 123
Miran Avatar answered Oct 14 '22 03:10

Miran


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"
like image 36
Sabri Meviş Avatar answered Oct 14 '22 03:10

Sabri Meviş