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.

  1. set weightsum="3" parent layout. means sum of entire layout_weights 3.

  2. set layout_weight="1" each of individual buttons. each individual button has 1/3rd size of parent.

  3. 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

Popular posts from this blog

How to connect android app to App engine -

gcc - MinGW's ld cannot perform PE operations on non PE output file -

php - display validation error message next to the textbox in codeigniter -