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

Setting a maximum width on a ViewGroup

One option which is what I did is to extend LinearLayout and override the onMeasure function. For example: public class BoundedLinearLayout extends LinearLayout { private final int mBoundedWidth; private final int mBoundedHeight; public BoundedLinearLayout(Context context) { super(context); mBoundedWidth = 0; mBoundedHeight = 0; } public BoundedLinearLayout(Context context, AttributeSet attrs) { super(context, attrs); TypedArray a = … 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

tech