Android: Drag View outside screen

点点圈 提交于 2019-12-01 04:24:10

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!