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

Native Development

Reply
New Contributor
nickmaher
Posts: 8
Registered: ‎09-27-2012
My Device: Dev Alpha
My Carrier: Telstra

Aligning text by baseline

 

I've got two Labels next to each other in a StackLayout with LeftToRight orientation. The first one is a large font, and the second one is a small font. I'd like to have them aligned vertically so that their baselines match. Is there any way to do this?

 

I was thinking I might need to switch to an AbsoluteLayout, and align them manually. If I do this, is there any way to measure the text so that I don't need to hardcode offsets? Perhaps a way to measure the width of a string with a given font, and get text metrics for a font (ascent/descent, etc)?

Please use plain text.
Developer
dkonigs
Posts: 243
Registered: ‎07-25-2008
My Device: Bold 9900

Re: Aligning text by baseline

I'm not sure if its public (RIM, please make it public if its not set so), but I wrote up a related feature request in the JIRA system a while back, which could use some upvoting:

 

Access to font metrics for UI layout purposes

https://www.blackberry.com/jira/browse/BBTEN-166

 

In this ticket, I pretty much describe a lot of what you're wanting to do here.

Please use plain text.
New Contributor
nickmaher
Posts: 8
Registered: ‎09-27-2012
My Device: Dev Alpha
My Carrier: Telstra

Re: Aligning text by baseline

Thanks. Looks like it's not public yet, but I'll check back a bit later.

Please use plain text.
Developer
HorizonXP
Posts: 133
Registered: ‎03-28-2011
My Device: BlackBerry 9900 & PlayBook
My Carrier: Bell

Re: Aligning text by baseline

It's public now.

I've just run into this precise issue right now, so I'm hoping that it gets resolved for the next release.

Founder of Pulsecode Inc. and taab
Authomator - Two-factor authentication codes on BlackBerry 10 - http://www.xitijpatel.com/ - Follow @xitijpatel
Is there a helpful or useful post in this thread? Click the thumbs up on it so that other people can find it more easily!
Please use plain text.
Developer
BGmot
Posts: 1,068
Registered: ‎11-24-2011
My Device: PlayBook
My Carrier: x

Re: Aligning text by baseline

Setting VerticalAlignment to Bottom for these Labels does not work?

Please use plain text.
New Contributor
nickmaher
Posts: 8
Registered: ‎09-27-2012
My Device: Dev Alpha
My Carrier: Telstra

Re: Aligning text by baseline

Thanks for the reply. The problem with VerticalAlignment Bottom is that larger fonts have more space below the baseline (e.g. for characters like g, q), so the baselines don't line up correctly.

 

I ended up just using a hardcoded vertical offset. A bit of a hack, and I was trying to avoid this, but it works well enough for now.

Please use plain text.
Developer
HorizonXP
Posts: 133
Registered: ‎03-28-2011
My Device: BlackBerry 9900 & PlayBook
My Carrier: Bell

Re: Aligning text by baseline

If the labels have the exact same font size, it does.

 

Otherwise, no.


Founder of Pulsecode Inc. and taab
Authomator - Two-factor authentication codes on BlackBerry 10 - http://www.xitijpatel.com/ - Follow @xitijpatel
Is there a helpful or useful post in this thread? Click the thumbs up on it so that other people can find it more easily!
Please use plain text.