Bound a View to drag inside RelativeLayout

前端 未结 3 1478
小鲜肉
小鲜肉 2021-01-04 22:36

I have created a draggable view inside RelativeLayout. But it seems to go beyond the RelativeLayout.

I simply

3条回答
  •  花落未央
    2021-01-04 23:02

    You should use rootView.getX() and rootView.getY() as the left and top bounderies... and (rootView.getX() + rootView.getWidth()) as the right and (rootView.getY() + rootView.getHeight()) for the bottom boundary.

    You have to write your boundary logic in onTouch() in the ACTION_MOVE case.

    Hope this helps.

提交回复
热议问题