0

can anybody tell how layout_weigh sum is working in android .I have given weighsum 100 for linear layout and layout_weight="33" for texview and layout_weight="67" for button .but textview is coming large size

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent" android:layout_height="wrap_content"
    android:background="#FFFFFF"
    android:weightSum="100">
    <TextView android:text="left" android:textColor="#000000" android:layout_width="fill_parent"
        android:layout_height="wrap_content" android:layout_weight="33" />
    <Button android:text="right"  android:layout_width="fill_parent"
        android:layout_height="wrap_content" android:layout_weight="67" />
</LinearLayout>

Thanks

user386430
  • 4,837
  • 13
  • 41
  • 45

2 Answers2

0
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:background="#FFFFFF"
     >

    <TextView
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:layout_weight="1"
        android:text="left"
        android:textColor="#000000" />

    <Button
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:layout_weight="1"
        android:text="right" />

</LinearLayout>

please remove android:weightSum="100" and try with this code.

kyogs
  • 6,766
  • 1
  • 34
  • 50
0

The Work on android:layout_weight is nothing but it is used to set dp for its Parent Layout.

It can be Sum of 1 or 10 or 100.

i.e.

1) 0.8 and 0.2

2) 80 and 20

3) 800 and 200 

All the three options are same

You can add the above weight to child layout. You can Refer Here.

Community
  • 1
  • 1
Bhavin
  • 6,020
  • 4
  • 24
  • 26