Position of a Child View in a HorizontalScrollView
I have a HorizontalScrollView with a series of CompoundButtons. I want to 开发者_如何学编程find the (x,y) for a given child view. I have tried using: getLocationOnScreen() getLocalVisibleRect() getChildVisibleRect()
like this: View tmpView = this.findViewById(viewId); Rect hitRect = new Rect();
tmpView.getLocalVisibleRect(hitRect);the hitRect is always 0,0 - 0,0.
I need the x,y mainly to scroll to a particular child view. Any help is greatly appreciated. Thanks.
Are you doing the getLocalVisibleRect() in OnCreate? You need to wait until android is finished setting up the layout before using getLocalVisibleRect, if you call it in OnCreate it won't work.
精彩评论