android - How to align horizontally 3 fix width buttons in LinearLayout? -
i have layout:
<linearlayout android:layout_width="match_parent" android:layout_height="wrap_content" android:orientation="horizontal" android:paddingtop="32dp"> <button android:layout_width="100dp" android:layout_height="wrap_content" android:text="button1"/> <button android:layout_width="100dp" android:layout_height="wrap_content" android:text="button2"/> <button android:layout_width="100dp" android:layout_height="wrap_content" android:text="button3"/> </linearlayout> i want align horizontally these 3 fix width buttons. me please ?
basically there 3 steps involved.
set weightsum="3" parent layout. means sum of entire layout_weights 3.
set layout_weight="1" each of individual buttons. each individual button has 1/3rd size of parent.
finally set layout_width="0dp", important because here don't have set width of view. set automatically layout handler.
<button android:layout_width="0dp" android:layout_height="wrap_content" android:text="button1" android:layout_weight="1"/> <button android:layout_width="0dp" android:layout_height="wrap_content" android:text="button2" android:layout_weight="1"/> <button android:layout_width="0dp" android:layout_height="wrap_content" android:text="button3" android:layout_weight="1"/> </linearlayout>
Comments
Post a Comment