android layout - Force a relative size for a button? -
i have 2 buttons in relative layout, both have android:layout_weight="50". long no button's text greater half screen weight, both buttons have same size. when 1 button's text gets long, buttons won't have same size anymore (please compare screenshot below). how can make 2 buttons equally sized, therefore each of them shall have width of half of screen size, giving them relative width android:layout_weight="50" both buttons end equally sized independent of text length? ok, if text cropped or that. hint!
my current xml code looks this:
<linearlayout android:orientation="horizontal" android:layout_width="fill_parent" android:layout_height="wrap_content"> <button android:layout_height="wrap_content" android:layout_width="wrap_content" android:layout_weight="50" android:text="left button left button left button left button"/> <button android:layout_height="wrap_content" android:layout_width="wrap_content" android:layout_weight="50" android:text="right button"/> </linearlayout> 
set android:layout_width="0dp" on both buttons.
the layout weights applied after button's widths have been calculated. when specify android:layout_width="wrap_content" width of text calculated before weights calculated, , controls sized contain text, because telling layout manager content of each button should wrap around text. if set widths 0dp, layout weights made equal irrespective of size of text within buttons , weights taken in account when layout sizes & positions calculated layout manager.
Comments
Post a Comment