Tuesday, December 14, 2010

[android-developers] Re: View width and calculated text width doesn't match

Does it work on stock Android, like the Nexus One? If you want to
send me your .apk, I'd be happy to try it for you.

On Dec 15, 12:45 am, Schoel <samuelsson.j...@gmail.com> wrote:
> Hello,
>
> I am trying to create a view that fits a text into a given text view.
> I've done a new view that has a custom XML attribute called
> minTextSize that is a dimension. Whenever text is set on the text
> view, it tries with all sizes from the desired (specified in the xml)
> down to minTextSize until it finds one that fits. This works perfectly
> on an emulator, I get the desired behaviour but when I try it on my
> HTC Desire, the calculated text width and the calculated width of the
> text view doesn't seem to match.
> I've tried both Paint.measureText, Paint.getTextWidths and
> Paint.getTextBounds, all with the exact same result. Around 9
> characters fit in the view but I have to write around 18 characters
> before it starts making the font size smaller.
> I use View.getWidth to measure the width of the view and it seems to
> be correct since it claims to take 392 pixels out of the 480 available
> (which looks about right).
> The only thing I can think of is that measureText and getWidth uses
> different units. Could that be the case? Do you have any other ideas
> for me?
> I've tried Stack Overflow and all answers I've seen uses one of the
> three methods in Paint mentioned above.
>
> I appriciate any help,
> Schoel

--
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to android-developers@googlegroups.com
To unsubscribe from this group, send email to
android-developers+unsubscribe@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en

No comments:

Post a Comment