Welcome!

Welcome to the official BlackBerry Support Community Forums.

This is your resource to discuss support topics with your peers, and learn from each other.

inside custom component

Java Development

Reply
New Contributor
Posts: 4
Registered: ‎09-21-2011
My Device: Blackberry Storm 9850
My Carrier: Generic
Accepted Solution

Scaling Using Device Dimensions For different BB Devices.

Hi All,

 

I just wanted to know if there was any other way besides scaling using base screen dimensions,to resize buttons in an app,so that they remain in proportion to the screen no matter what the dimensions..i.e no matter what the model used 9850 or 9930 or any other using OS 7.0

 

I tried using certain factors which were common to both the screens dimensions 640x480 and 800x480.But I just dont think its a generalised enough approach.

 

Any Ideas?

Developer
Posts: 19,623
Registered: ‎07-14-2008
My Device: Not Specified

Re: Scaling Using Device Dimensions For different BB Devices.

I agree that just using dimensions is not generalized enough.  You need to factor in the actual screen resolution.  And then, if it is a touch screen, things like buttons need to be large enough to hit with fat fingers....

 

Here is code that might help:

int screenResH = Display.getHorizontalResolution();
int screenResV = Display.getVerticalResolution();
float PIXELS_IN_ONE_CM = ((float)Math.max(screenResH, screenResV)) / 100f;

 

Now if you are on a touch screen then the button should be I think at least .7 cm to be big enough to hit.  And you can calculate that using the above and so button size will look the same size on all devices and be equally easy to hit. 

 

Another alternative is to take the default font and use its height to factor things.  This will mean your scaling will vary depending on what the user has specified.  So if your user has very good eyes and has specified a small font size to get more data on their screen, then you will scale to smaller sizes.  On the other hand, old blind people like me will see big images.

 

The down side of this is that all devices will look different.  There is an argument that says people want their app to look the same everywhere.  Personally I don't think that is possible on a BlackBerry. 

 

Does this help? 

New Contributor
Posts: 4
Registered: ‎09-21-2011
My Device: Blackberry Storm 9850
My Carrier: Generic

Re: Scaling Using Device Dimensions For different BB Devices.

hi,

 

Thanks for your reply Peter.:-)

 

I already tried something similar,i used a display.getHeight method to get height of display and i used that along with factors like 0.025 which are common to both screen sizes 640x480 and 800x480,The problem is it won't work for any other screen resolutions.

 

or i could take a base screen size like 320x480 and use that for scaling the devices screen sizes.and get the button size from that

 

But i just wanted a 2 knw if a different,more effective approach was possible.

 

Help!!

 

 

 

 

 

Developer
Posts: 19,623
Registered: ‎07-14-2008
My Device: Not Specified

Re: Scaling Using Device Dimensions For different BB Devices.

I am not sure you have understood what I was saying.

 

I think it is important to scale things so that

1) they are legible on the screen

2) The user can interact with them.

 

So I ignore the actual number of pixels on the screen in terms of laying things out.  Instead the code I have given you is intended to calculate the number of pixels used in 1 cm on the screen.  So you can scale using that to make sure that things are big enough.  So regardless of the screen, I can take and scale it to a specific size on the screen - visible size, not number of pixels.  

 

Exactly the same thing happens to fonts.  If you look on the BlackBerry you can change the font.  But the sizes you specify are points, they are actual size on the screen.  So if you select BlackBerry Alpha Sans, 8 on a 9900, the and then ask if how high it is

(font.getHeight()l

it returns a result in pixels.  If you do the same thing, using the same font, on the Torch, you will find that the number of pixels used on the Torch is a lot smaller.  The font is the same physical size on the screen, but uses more pixels on the 9900 because the actual resolution of that screen is higher.

 

There is a confusion here.  Most people, I believe incorrectly, use the term screen resolution to mean the number of pixels on the screen.  To me that is just the screen size,  The resolution is the pixels per inch.  And pixels per inch is what the code I gave effectively calculates (I use centimeters because I am not in the US and cm is more commonly used here than inch). 

 

Anyway, I don't think you understood what I was saying before and you thought I was just doing the same as you.  I don't think I was.  Please read it again and see if you understand better now.   

New Contributor
Posts: 4
Registered: ‎09-21-2011
My Device: Blackberry Storm 9850
My Carrier: Generic

Re: Scaling Using Device Dimensions For different BB Devices.

Thanks.

 

i get it now.Will try implementing that.:-)

and will let u knw how it goes.

Developer
Posts: 723
Registered: ‎03-12-2009
My Device: Playbook

Re: Scaling Using Device Dimensions For different BB Devices.

I found that using Pts works very well. i.e. If you use 14 point fonts (and UI scaled based on Pt size) it will be much easier to support than if hardcoding pixel values. Also it saves you the headache of worrying about PPI, etc, etc. Let OS worry about that.
New Contributor
Posts: 4
Registered: ‎09-21-2011
My Device: Blackberry Storm 9850
My Carrier: Generic

Re: Scaling Using Device Dimensions For different BB Devices.

Hi,

 

I used it..and its working fine now,

Thanks Peter and dnepr!!!!!!