Code example for LinearLayout

Methods: getChildCountremoveViewAt

        removeButton.setOnClickListener(new View.OnClickListener() {
            public void onClick(View v) {
                if (container.getChildCount() > 0) {
                    // Removing a view will cause a LayoutTransition animation 
                    container.removeViewAt(Math.min(1, container.getChildCount() - 1));
        // Note that this assumes a LayoutTransition is set on the container, which is the 
        // case here because the container has the attribute "animateLayoutChanges" set to true 
        // in the layout file. You can also call setLayoutTransition(new LayoutTransition()) in 
        // code to set a LayoutTransition on any container. 
        LayoutTransition transition = container.getLayoutTransition();
        // New capability as of Jellybean; monitor the container for *all* layout changes 
        // (not just add/remove/visibility changes) and animate these changes as well. 
Connect your IDE to all the code out there  Get Codota for Java