How to get a button sized by its background image?

61 views
Skip to first unread message

Ben

unread,
Feb 19, 2014, 6:11:07 AM2/19/14
to codenameone...@googlegroups.com
I'd like to define the look and size of a button by an image or more images for different DPI and set its text by localization.
I tried it with image-border, component-background and button-icon, with and without multi-images but nothing really worked for all DPI.
So what is the correct way to create a button from images with fixed sizes?

Shai Almog

unread,
Feb 19, 2014, 12:53:08 PM2/19/14
to codenameone...@googlegroups.com, ben.nus...@spherix.ch
What isn't working for all DPI's with multi-image's and icons?
Multi-images are specifically designed for all DPI's.

ben.nus...@spherix.ch

unread,
Feb 19, 2014, 1:21:48 PM2/19/14
to codenameone...@googlegroups.com, ben.nus...@spherix.ch
The button for iPhones should be exactly 640x88px.
I tried to use multi-images for the 9 image-borders with top and bottom images of 34px height (for the 480x854px high density DPI).
The result was a bit too high.
1. was this the right approach or how can you build buttons with a fixed height?
2. is there a possibility to differentiate between iPhone4 and iPhone5 resolution within the multi-image?

thanks for your help

Shai Almog

unread,
Feb 20, 2014, 2:26:21 AM2/20/14
to codenameone...@googlegroups.com, ben.nus...@spherix.ch
An exact size in pixels is a problematic proposition. I was talking about a multi image icon which you can set to an exact size for a specific DPI.

Other than that an exact size in pixels would be a bad idea since font sizes change slightly you can control the exact size though by adding padding to increase size to the image border approach.

You can set the size explicitly using setPreferredSize() but that is generally a bad idea since it will break the UI for other device resolutions hence sabotaging our effort at cross platform.
Reply all
Reply to author
Forward
0 new messages