Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

android weightSum not working properly

I have a layout with three elements and its orientation is 'horizontal'

I want to fix the size that each element occupy in my layout.

first element should take 40% of the total space then second element should occupy 5% and third one should occupy remaining 55% space.

My layout look like this:

 <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >


<LinearLayout
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:orientation="horizontal"
    android:weightSum="100" >

    <TextView
        android:id="@+id/outletname"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_weight="40"
        android:text="@string/outlet_name2" />

    <TextView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_weight="5"
        android:text=": " />

    <TextView
        android:id="@+id/outletnamevalue"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_weight="55"
        android:text="abcdefttt" />
</LinearLayout>
</LinearLayout>

text in 'TextView' will change dynamically , So I want to keep the constant space for elements irrespective of the content in views...

like image 923
brig Avatar asked Apr 11 '12 09:04

brig


1 Answers

In order to make weight effective, you must also need to set the widths of your TextViews to 0dp.

android:layout_width="0dp"
like image 88
waqaslam Avatar answered Oct 14 '22 18:10

waqaslam