Bearded-Hen / Android-Bootstrap

Bootstrap style widgets for Android, with Glyph Icons
MIT License
7.29k stars 1.43k forks source link

[BootstrapDropdown] Calculation of longest item is wrong #191

Open StNekroman opened 7 years ago

StNekroman commented 7 years ago

Currently you calculate it as: measuretext(getLongestItemText()) + paddingLeft + paddingRight. But that it not corrent, because with of "WWW" will be longer then "iii", while length of both string is the same. In other words: image

And final result of bug is here: device-2017-01-03-212645

In this case, my longest string was "EUR". But, as you see, even "EUR" doesn't fit in the line.

StNekroman commented 7 years ago

Additionaly,

return (float) (DimenUtils.dpToPixels(mPaint.measureText(text)));

is not correct, because measureText output is already in pixels.

Although,

mPaint.setTextSize(baselineDropDownViewFontSize * bootstrapSize);

looks like isn't correct as well due to http://stackoverflow.com/questions/6232541/android-measuretext-return-pixels-based-on-scaled-pixels

StNekroman commented 7 years ago

For debugging needs I set up

<dimen name="bootstrap_dropdown_default_item_left_padding">0dp</dimen>
<dimen name="bootstrap_dropdown_default_item_right_padding">0dp</dimen>

in order to see clean width, without padding adn I got: image

So, looks like, calculationo of item width is wrong from the begining even for "EUR", which was chosen as longest one.