vxh.viet
7/8/2016 - 7:37 AM

Effortless View's Expand, Collapse animation

Effortless View's Expand, Collapse animation

Source: StackOverflow

Question: How to quickly add expand, collapse animation to View.

Answer:

For api >= 11 (Doc)

You will have to set this property for all topmost layouts (Stack), which are involved in the shift. If you now set the visibility of one layout to GONE, the other will take the space as the disappearing one is releasing it. There will be a default animation which is some kind of "fading out"

<LinearLayout android:id="@+id/container"
android:animateLayoutChanges="true"
...
 />

Plain, quick and simple, no need to messing with Animation.

Example of a recycler list dismisses another View on scrolling:

    mRecyclerView.addOnScrollListener(new RecyclerView.OnScrollListener() {
            @Override
            public void onScrolled(RecyclerView recyclerView, int dx, int dy) {
                super.onScrolled(recyclerView, dx, dy);
                if(recyclerView.getScrollY() != dy){
                    if(mVideoViewWrapper.getVisibility() == View.VISIBLE){
                        mVideoViewWrapper.setVisibility(View.GONE);
                    }
                }
            }
        });