How do browsers calculate width when child depends on parent, and parent’s depends on child’s

To explain this, I will start with a more simplified example that will produce the same output: <div style=”display:inline-block”> <img src=”https://via.placeholder.com/1000×100″> </div> <div style=”display:inline-block”> <img src=”https://via.placeholder.com/1000×100″ style=”max-width:100%”> </div> <div style=”display:inline-block”> <!– even a big explicit width specified won’t change the behavior –> <img src=”https://via.placeholder.com/1000×100″ style=”wdith:2000px;max-width:100%”> </div> <div style=”display:inline-block”> <img src=”https://via.placeholder.com/1000×100″ style=”width:100%”> </div> We have an … Read more

How to calculate the width of the scroll bar?

There is a jQuery plugin that can help with this: https://github.com/brandonaaron/jquery-getscrollbarwidth/blob/master/jquery.getscrollbarwidth.js Also, from http://www.alexandre-gomes.com/?p=115 Here is some code that may help. This creates a hidden <p> element at 100% width inside a <div> with a scrollbar, then calculates the <div> width – the <p> width = scroll bar width. function getScrollBarWidth () { var inner … Read more

How to find android TextView number of characters per line?

Try this: private boolean isTooLarge (TextView text, String newText) { float textWidth = text.getPaint().measureText(newText); return (textWidth >= text.getMeasuredWidth ()); } Detecting how many characters fit will be impossible due to the variable width of the characters. The above function will test if a particular string will fit or not in the TextView. The content of … Read more

How get a string width in Libgdx?

BitmapFont API < 1.5.6 To mesure the width of a String you use your Font and get the bounds of the String, you are going to draw. BitmapFont.getBounds(String str).width BitmapFont API You can get the height to for the right offset for drawing too. Just replace width with height. In addition for multiline texts use … Read more

XML Table layout? Two EQUAL-width rows filled with equally width buttons?

To have buttons in rows where buttons are the same size you need to do. <LinearLayout android:orientation=”horizontal” android:layout_width=”fill_parent” android:layout_height=”fill_parent”> <Button android:layout_weight=”1″ android:layout_height=”wrap_content” android:layout_width=”0dip”/> <Button android:layout_weight=”1″ android:layout_height=”wrap_content” android:layout_width=”0dip”/> </LinearLayout> And fill in the other xml properties for your buttons. The magic is in the layout_weight and width properties. You don’t need the Table layout. These properties … Read more

Measuring the pixel width of a string

On iPhone OS it is slightly different, instead look at the NSString UIKit Additions Reference. The idea is the same as in Cocoa for Mac OS X, but there are more methods. For single lines of text use: – (CGSize)sizeWithFont:(UIFont *)font forWidth:(CGFloat)width lineBreakMode:(UILineBreakMode)lineBreakMode And for multiline texts use: – (CGSize)sizeWithFont:(UIFont *)font constrainedToSize:(CGSize)size lineBreakMode:(UILineBreakMode)lineBreakMode The use … Read more