Android RecyclerView smooth scroll to view that's animating their height

前端 未结 2 1303
孤城傲影
孤城傲影 2021-02-15 18:48

I have a RecyclerView with Expandable Child Views, when the child ViewGroup is clicked it inflates an amount of views animating the ViewGroup height from 0 to the measured viewg

相关标签:
2条回答
  • 2021-02-15 18:55

    My solution was to constant check for view bottom within applyTransformation method, and compare it with RecyclerView height, if the bottom get higher than the RV height, i scroll by the diff values:

    final int bottom = collapsible_content.getBottom();
    final int listViewHeight = mRecyclerView.getHeight();
    if (bottom > listViewHeight) {
        final int top = collapsible_content.getTop();
        if (top > 0) {
            mRecyclerView.smoothScrollBy(0, Math.min(bottom - listViewHeight + mRecyclerView.getPaddingBottom(), top));
        }
    }
    

    The trick was to use Math.min to get the view top, so it don't scroll up making the top not visible.

    Solution based on ListViewAnimations

    0 讨论(0)
  • 2021-02-15 19:00

    Add an animationlistener and start the scrolling of the recyclerview after the expanding animation is finished.

    0 讨论(0)
提交回复
热议问题