you can try using this instead: http://developer.android.com/reference/android/text/Layout.html#getDesiredWidth(java.lang.CharSequence, int, int, android.text.TextPaint)
Or just copy the source code for Paint without the Ceil :) On Wednesday, December 11, 2013 8:28:09 PM UTC+2, Harri J. Smatt wrote: > > Why are you using one pixel sized text for measuring? It can only cause > you trouble if the rounding did not occur before automatically. Make text > size somewhere near to 1000 pixels in size (or higher if the platform > allows) and you have basis for calculating sub pixel values on certain > precision at least. > > — > H > > On 11 Dec 2013, at 00:37, Ab <[email protected] <javascript:>> wrote: > > Oh, well, that seems definitive and unlikely to have a workaround. > Though, it's It is and unfortunate, and not backwards compatible, for > someone who renders text... > > On Tuesday, 10 December 2013 19:21:54 UTC-5, RichardC wrote: >> >> Can't help you to fix this but have researched the change... >> >> Source for the return value of Paint.measureText I see: >> Android 17 >> return w*mInvCompatScaling; >> Android 18 >> return (float) Math.ceil(w*mInvCompatScaling); >> >> The change was done for the follow reasons: >> >> https://github.com/android/platform_frameworks_base/commit/8e04840f38a16f806754dfca3de50c2548e67913 >> >> >> >> On Tuesday, December 10, 2013 8:45:45 PM UTC, Ab wrote: >>> >>> I make heavy use of the Paint.measureText() method and was surprised to >>> find that in 4.4 thefloat this method returns is always rounded up. In >>> previous versions, no rounding occurred. I ran the below code on a 4.0.4 >>> device and a 4.4 device. The results for the 4.0.4 device are first, the >>> results for the 4.4 device are second. >>> >>> Any suggestions of how I can get unrounded values in 4.4, possibly there >>> is a new attribute for Paintthat I missed? >>> >>> @Overrideprotected void onCreate(Bundle savedInstanceState) { >>> super.onCreate(savedInstanceState); >>> >>> Paint p = new Paint(); >>> p.setTypeface(Typeface.create(Typeface.SANS_SERIF, Typeface.NORMAL)); >>> p.setTextSize(1); >>> p.setAntiAlias(true); >>> p.setSubpixelText(true); >>> >>> Log.e("T", p.measureText("T")+""); >>> Log.e("h", p.measureText("h")+""); >>> Log.e("e", p.measureText("e")+""); >>> Log.e("L", p.measureText("L")+""); >>> Log.e("a", p.measureText("a")+""); >>> Log.e("z", p.measureText("z")+""); >>> Log.e("y", p.measureText("y")+""); >>> Log.e("w", p.measureText("w")+"");} >>> >>> 4.0.4: >>> >>> 0.59375 0.5625 0.515625 0.546875 0.546875 0.5 0.5 0.75 >>> >>> 4.4: >>> >>> 1.0 1.0 1.0 1.0 1.0 1.0 1.0 1.0 >>> >>> > -- > You received this message because you are subscribed to the Google > Groups "Android Developers" group. > To post to this group, send email to > [email protected]<javascript:> > To unsubscribe from this group, send email to > [email protected] <javascript:> > For more options, visit this group at > http://groups.google.com/group/android-developers?hl=en > --- > You received this message because you are subscribed to the Google Groups > "Android Developers" group. > To unsubscribe from this group and stop receiving emails from it, send an > email to [email protected] <javascript:>. > For more options, visit https://groups.google.com/groups/opt_out. > > > -- You received this message because you are subscribed to the Google Groups "Android Developers" group. To post to this group, send email to [email protected] To unsubscribe from this group, send email to [email protected] For more options, visit this group at http://groups.google.com/group/android-developers?hl=en --- You received this message because you are subscribed to the Google Groups "Android Developers" group. To unsubscribe from this group and stop receiving emails from it, send an email to [email protected]. For more options, visit https://groups.google.com/groups/opt_out.

