开发者

Position of a Child View in a HorizontalScrollView

开发者 https://www.devze.com 2022-12-31 10:00 出处:网络
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:

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.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号