我有一个带有一系列 CompoundButton 的 HorizontalScrollView。我想找到给定 subview 的 (x,y)。我试过使用: getLocationOnScreen() getLocalVisibleRect() getChildVisibleRect()
像这样:
查看 tmpView = this.findViewById(viewId);
矩形 hitRect = new Rect();
tmpView.getLocalVisibleRect(hitRect);
hitRect 始终为 0,0 - 0,0。
我主要需要 x,y 来滚动到特定的 subview 。任何帮助是极大的赞赏。谢谢。
最佳答案
您是否在 OnCreate 中执行 getLocalVisibleRect()? getLocalVisibleRect需要等到android设置完layout后才能使用,如果在OnCreate中调用是不行的。
关于android - subview 在 HorizontalScrollView 中的位置,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2858448/