RecyclerTreeView icon indicating copy to clipboard operation
RecyclerTreeView copied to clipboard

Scroll up last visible item while expanding

Open vinayjoglekar opened this issue 7 years ago • 1 comments

Hi Team, I am trying to implement a functionality where I can scroll up and expand childs of node on click of node whose all childs are not visible on screen. Please help me if there is any workaround for the same.

Thanks in advance.

vinayjoglekar avatar Feb 08 '18 13:02 vinayjoglekar

Try this code

adapter.setOnTreeNodeListener(new TreeViewAdapter.OnTreeNodeListener() {
            @Override
            public boolean onClick(TreeNode node, RecyclerView.ViewHolder holder) {
                if (!node.isLeaf()) {
                    onToggle(!node.isExpand(), holder);
                    int position = holder.getAdapterPosition();
                    int distanceInPixels;
                    View firstVisibleChild = rv.getChildAt(0);
                    int itemHeight = firstVisibleChild.getHeight();
                    int currentPosition = rv.getChildAdapterPosition(firstVisibleChild);
                    int p = Math.abs(position - currentPosition);
                    if (p > 5) distanceInPixels = (p - (p - 5)) * itemHeight;
                    else       distanceInPixels = p * itemHeight;
                    linearLayoutManager.scrollToPositionWithOffset(position, distanceInPixels);
                }
                return false;
            }
});

naveen3186 avatar May 09 '21 13:05 naveen3186