I am trying to dynamically create and then move an image in Android activity. However, the setX () and setY () methods seem incorrect. It correctly sets the position of the image when creating and placing it, but any attempt to update it results in the image being placed in the wrong place. For example, the image moves along the following code:
ImageView image; RelativeLayout layout = (RelativeLayout)findViewById(R.id.activity_this); if(action == MotionEvent.ACTION_DOWN){ image = new ImageView(MyClass.this); layout.addView(image, width, height); image.setX(206); image.setY(206); } else if(action == MotionEvent.ACTION_MOVE){ if(image != null){ image.setX(206); image.setY(206); } }
At ACTION_MOVE, the image is moved even if the position values โโx and y remain unchanged. The parent of the image remains unchanged. The size remains the same. If I get the values โโof x and y, it will still say 206, but will no longer be placed in (206, 206). I am lost why this is happening. I cannot find any indication that the image was changed, except that it physically changes the location.
source share