Reputation: 10777
I am trying to get the x and y coordinates of the center of the screen. Here is what i tried:
Display display = getWindowManager().getDefaultDisplay();
final Point size = new Point();
display.getSize(size);
height = size.y;
float centerY=height/2;//i expect this is the y coordinate of center
But this does not work, when i say:
SomeImageView.setY(centerY);
I do not see it at the center of the screen. Can anyone help me with this?
Thanks
Upvotes: 4
Views: 12731
Reputation: 16526
I guess you're correctly getting the center coordinates, but setY
is setting the position of the bottom edge of your ImageView
. Off the top of my head, you may try something like
SomeImageView.setY(height - SomeImageView.getDrawable().getIntrinsicHeight());
Upvotes: 4