WeightSum property in the Java programming

WeightSum property is different from weight property. this property is only use in linear. and it’s also devide widgets or linear size like weight property but it’s not work like weight property.

weightsum is devide inside of the linear for the widgets (textview, EditText, imageview etc) or linear. it’s helpful to devide equal size inside of linear. for example see code below.

Code

<LinearLayout

android:id=”@+id/linear17″

android:layout_width=”match_parent”

android:layout_height=”match_parent”

android:padding=”8dp”

android:orientation=”vertical”

android:weightSum=”4″>

<Button

android:id=”@+id/button2″

android:layout_width=”wrap_content”

android:layout_height=”wrap_content”

android:padding=”8dp”

android:text=”Button”

android:textSize=”12sp”

android:textColor=”#000000″

android:layout_weight=”1″/>

<Button

android:id=”@+id/button3″

android:layout_width=”wrap_content”

android:layout_height=”wrap_content”

android:padding=”8dp”

android:text=”Button”

android:textSize=”12sp”

android:textColor=”#000000″

android:layout_weight=”1″/>

<Button

android:id=”@+id/button4″

android:layout_width=”wrap_content”

android:layout_height=”wrap_content”

android:padding=”8dp”

android:text=”Button”

android:textSize=”12sp”

android:textColor=”#000000″

android:layout_weight=”1″/>

</LinearLayout>

</LinearLayout>

In This code i set the linear weightsum is 4 and inside of linear create three button’s and set their weight one. it means the linear will devide 4 part to inside. but their are three button inside of linear and i was set weight sum 4. So button will take equal size devided by 4 and 1 equal place will empty because button is only three and set weight sum is 4.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

This site uses Akismet to reduce spam. Learn how your comment data is processed.