Android setX() and setY() behaving weird

后端 未结 6 1467
情歌与酒
情歌与酒 2021-01-17 23:10

I am trying to dynamically create and then move an image in an Android activity. However, the setX() and setY() methods seem to not work correctly. It correctly sets the pos

6条回答
  •  青春惊慌失措
    2021-01-17 23:31

    Really, this shouldn't be happening. Alternatively, try setting another variable and setting x and y to it, or get x and get y and add a 0 to each one of them for same location.

    As stated in Android - Use of view.setX() and setY in api 8, if you have searched, there is another solution that also works even before api 8. LayoutParams works like this -

    RelativeLayout.LayoutParams params = new RelativeLayout.LayoutParams(LayoutParams.WRAP_CONTENT,LayoutParams.WRAP_CONTENT); //WRAP_CONTENT param can be FILL_PARENT
    params.leftMargin = 206; //XCOORD
    params.topMargin = 206; //YCOORD
    childView.setLayoutParams(params);
    

    There is more information there. I hope this helps

提交回复
热议问题