tags:

views:

96

answers:

2

Hi!

Can anyone give me a tip for how to get the position of a view what is a child of an AbsoluteLayout? I want to do this for drag and drop the selected view.

Thank you!

+2  A: 

Hi
AbsoluteLayout is deprecated, so probably you would have to provide your own drag&drop layout by extending ViewGroup. In general, layout it is responsible for positioning children widgets. This is done in onLayout() method which you would have to override. It will be probably something like this:


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);
      }
   }
}

So, by implementing your own DragAndDropLayout - you know the position of your children. But, maybe there is simplier solution.
Regards!

Ramps
+2  A: 

To know where a child is in its parent, simply call getLeft() and getTop(). Also, do not use AbsoluteLayout :)

Romain Guy