[英]How can I get the position of a view in an AbsoluteLayout?
任何人都可以给我一个提示,如何获得一个视图的位置什么是AbsoluteLayout的孩子? 我想这样做是为了拖放选定的视图。
谢谢!
不推荐使用AbsoluteLayout,因此您可能需要通过扩展ViewGroup来提供自己的拖放布局。 一般来说,布局它负责定位子窗口小部件。 这是在onLayout()方法中完成的,您必须覆盖它。 它可能是这样的:
protected void onLayout(boolean changed, int l, int t, int r, int b) {
final int count = getChildCount();
for(int i=0; i<count; i++){
final View child = getChildAt(i);
if(GONE != child.getVisibility()){
//position child
child.layout(left, top, right, bottom);
}
}
}
因此,通过实现自己的DragAndDropLayout - 您知道您孩子的位置。 但是,也许有更简单的解决方案。
问候!
要知道孩子在其父级中的位置,只需调用getLeft()和getTop()。 另外,不要使用AbsoluteLayout :)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.