AndroidTreeView icon indicating copy to clipboard operation
AndroidTreeView copied to clipboard

How to scroll to show a node?

Open ModestinoAndre opened this issue 9 years ago • 5 comments

Hi.

I have a big tree and I need to make a specific node visible (on screen center). In other words, I need scroll to that node programmatically. For example: treeView.scrollTo(node127); Can you help me?

Sorry my bad english.

Thanks!

ModestinoAndre avatar Apr 11 '16 20:04 ModestinoAndre

Sorry for late response, TreeView is just ScrollView so you can work with tree in the same way. You can try to play with scrollTo method

bmelnychuk avatar Apr 27 '16 15:04 bmelnychuk

Hi. Sorry but AndroidTreeView not ScrollView... is just Class, so. How to use TreeView like ScrollView ? I need to pass AndroidTreeView.getView() into PlaceHolder, how I can do this.

p.s. Sorry for my bad english. Thanks alot.

1240 avatar Jun 06 '16 15:06 1240

AndroidTreeView.getView() is ScrollView, you can check implementation, you should be able to add this to any container. This can be also FrameLayout if you enable 2d scrolling (see example)

bmelnychuk avatar Jun 06 '16 15:06 bmelnychuk

Anyone had luck trying this ? scrollViewTreeView?.scrollTo doesn't have any effect

upon using scrollview->scrollTo

 if (getChildCount() > 0) {
            View child = getChildAt(0);
            x = clamp(x, getWidth() - mPaddingRight - mPaddingLeft, child.getWidth());
            y = clamp(y, getHeight() - mPaddingBottom - mPaddingTop, child.getHeight());
            if (x != mScrollX || y != mScrollY) {
                super.scrollTo(x, y);
            }
        }

getChildCount = 1 and width and height are always the same (total size of scrollView) instead of the child element being focused to

altagir avatar Nov 19 '19 18:11 altagir

Please see this answer:

https://github.com/bmelnychuk/AndroidTreeView/issues/152#issuecomment-614309243

alierdogan7 avatar Apr 15 '20 22:04 alierdogan7