Ok… here it is:
The first thing you want to do is define a width that you will use as a reference point. In my case I am developing for portrait orientation and picked 480 x 720 as a reference.
Once the screen is created, grab your scale by doing the following:
[java]
float refWidth = 480;
float guiScale = refWidth/screen.getWidth();
[/java]
Now that you have your scale factor, when you create an element, do the following:
[java]
float buttonWidth = 300 * guiScale;
float buttonHeight = 60 * guiScale;
ButtonAdapter ba1 = new ButtonAdapter(screen, UIDUtil.getUID(),
Vector2f.ZERO,
new Vector2f(buttonWidth, buttonHeight)
);
screen.addElement(ba1);
ba1.setPosition(
screen.getWidth()/2-(buttonWidth/2),
screen.getHeight()/2-(buttonHeight/2)
);
[/java]
Another trick is using the pixel width of the ui image… say you have a background image that is a portion of a 1024 x 1024 image (say 1024 x 245) and you need this to fill the top portion of your app. You would:
[java]
float headerScale = screen.getWidth()/1024;
header = new Element(
screen,
“header”,
Vector2f.ZERO,
new Vector2f(1024headerScale,245headerScale),
Vector4f.ZERO,
null
);
header.setTextureAtlasImage(main.getTextureUIAtlas(), main.getUICoords(RegionName.Header));
[/java]
In my case, I need TextElements to accurately display in at certain places in the header image, I chose to use the pixel width in this case, so I could measure out where in the image the text should display and then multiply this by headerScale to have it display in the proper place no matter what device the app is being run on.
Hopefully this is helpful. Do let me know if there are any questions about how I did this.