I'm using a FrameLayout on top of Andengine camera to add a button. I need to align the button to a sprite on the andengine camera.
I'm using gravity top in the frame layout and adding top padding to shift the button down. Works while on the development device. But because of the RatioResolutionPolicy, on a different device with different screen size, the alignment does not work.
I am wondering how to find the device screen Display co-ordinates that would exactly coincide with the AndEngine camera co-ordinates. I tried to figure out the ratio and assign the padding but is not working. Can anyone guide me on how to find the co-ordinates on the screen Display that would coincide exactly with the co-ordinates on the AndEngine camera?
Really stuck with this since two days. Any help would be greatly appreciated.
Closest i reached was using this (Button shifts but this is still not exact):
//get actual screen height of device to find ratio
Display display = getWindowManager().getDefaultDisplay();
Point size = new Point();
display.getSize(size);
int height = size.y;
int width = size.x;
//normal ratio logic
int heigntUsedByCamera = width * CAMERA_HEIGHT / CAMERA_WIDTH;
int requiredPaddingForBtnOnFrameLayout = (height - heigntUsedByCamera)/2;
In this one I'm expecting the button X to be exactly where the CAMERA starts
What is going wrong here?
OR Is there a better way to add a native button inside the AndEngine Camera?
See Question&Answers more detail:os