TableLayout weight sum issues

Dan James Palmer picture Dan James Palmer · Jun 3, 2013 · Viewed 16.1k times · Source

I'm trying to implement a 40/60 percent split in my TableLayout but I'm having no luck. When testing the code on my Android Device the left TextView still takes up what looks like 60%, instead of 40%.

    <TableLayout

    android:id="@+id/agentStatusTable"
    android:layout_height="wrap_content"
    android:layout_width="fill_parent"
    android:layout_gravity="center|top"
    android:visibility="visible"
    android:background="@drawable/curvedbg"
    android:layout_marginLeft="10sp"
    android:layout_marginRight="10sp"
>

<TableRow android:id="@+id/webiprow" android:layout_marginTop="14sp" android:gravity="center_vertical" android:background="#e5e6e6" android:minHeight="45sp" android:weightSum="1">
<TextView android:paddingRight="10dp" android:id="@+id/webiptitle" android:text="@string/webip" android:textColor="#000000" android:textSize="15sp" android:layout_weight="0.40" android:gravity="right"></TextView> 
<TextView android:paddingRight="10dp" android:id="@+id/webiptext" android:textColor="#000000" android:textSize="15sp" android:layout_weight="0.60" android:gravity="right"></TextView> 
</TableRow>

<TableRow android:id="@+id/webportrow" android:layout_marginTop="6dp" android:layout_marginBottom="14sp"  android:gravity="center_vertical" android:minHeight="45sp" android:weightSum="1">
<TextView android:paddingRight="10dp" android:id="@+id/webporttitle"  android:layout_weight="0.40"  android:text="@string/webport" android:textColor="#000000" android:textSize="15sp" android:gravity="right"></TextView> 
<EditText android:paddingRight="10dp" android:inputType="number"  android:layout_weight="0.60"  android:id="@+id/EditText01" android:text="@+id/EditText01"></EditText></TableRow>

</TableLayout>

Answer

anddevmanu picture anddevmanu · Jun 3, 2013

In the TextTiew and EditText where you use layout_weight, set height to wrap_content and width to 0dp.

android:layout_width="0dp"
android:layout_height="wrap_content"