4

I have an activity where users can drag and drop around some buttons.
All my draggable views are inside a RelativeLayout and to drag them around I change their top and left margins.
Everything works perfect, except that when I drag the views close to the right and bottom edge of the screen, they shrink instead of being drawn outside the screen. Is there any way for having the same behaviour on the all edges of the screen (currently only works fine on the top and left edge).

I guess I can have a left and top negative margin. But when I have left margin > screen width or top margin > screen height the images shrink.

Suragch
  • 484,302
  • 314
  • 1,365
  • 1,393
ffleandro
  • 4,039
  • 4
  • 33
  • 48

1 Answers1

1

To implement custom positioning of views inside a ViewGroup the best way is to implement your custom ViewGroup overriding onLayout().

It is not that difficult and I explained how to do it here. (the question is newer and has more visibility)

Edit: You might also want to look into the Drag and Drop Api here. Thanks to Zainodis for the comment.

Community
  • 1
  • 1
Gil Vegliach
  • 3,542
  • 2
  • 25
  • 37
  • 1
    What bugs me about this: Android provides Drag & Drop functionality, so would it not make sense to provide a view that can actually handle drag & drop without distorting the draggable views...? Instead of everyone having to re-invent the wheel. – AgentKnopf Sep 07 '15 at 10:48