问题
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.
回答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.
来源:https://stackoverflow.com/questions/13009318/android-drag-view-outside-screen