4

In my layout I have two different LinearLayouts. The first one is this:

    <LinearLayout
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:orientation="vertical" >

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content" >

        <TextView
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_weight="8"
            android:gravity="center"
            android:text="@string/lblPais" />

        <TextView
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_weight="1"
            android:gravity="center"
            android:text="@string/lblJ" />

        <TextView
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_weight="1"
            android:gravity="center"
            android:text="@string/lblG" />

        <TextView
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_weight="1"
            android:gravity="center"
            android:text="@string/lblP" />

        <TextView
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_weight="1"
            android:gravity="center"
            android:text="@string/lblPF" />

        <TextView
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_weight="1"
            android:gravity="center"
            android:text="@string/lblPC" />

        <TextView
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_weight="1"
            android:gravity="center"
            android:text="@string/lblDif" />

        <TextView
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_weight="1"
            android:gravity="center"
            android:text="@string/lblPuntos" />

    </LinearLayout>

And the second one is this layout:

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:weightSum="15" >

        <TextView
            android:id="@+id/lblPais1"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_weight="8"
            android:gravity="center"
            android:text="@string/lblPais" />

        <TextView
            android:id="@+id/lblJ1"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_weight="1"
            android:gravity="center"
            android:text="@string/lbl0" />

        <TextView
            android:id="@+id/lblG1"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_weight="1"
            android:gravity="center"
            android:text="@string/lbl0" />

        <TextView
            android:id="@+id/lblP1"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_weight="1"
            android:gravity="center"
            android:text="@string/lbl0" />

        <TextView
            android:id="@+id/lblPF1"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_weight="1"
            android:gravity="center"
            android:text="@string/lbl0" />

        <TextView
            android:id="@+id/lblPC"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_weight="1"
            android:gravity="center"
            android:text="@string/lbl0" />

        <TextView
            android:id="@+id/lblDif1"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_weight="1"
            android:gravity="center"
            android:text="@string/lblPtsVacio" />

        <TextView
            android:id="@+id/lblPuntos1"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_weight="1"
            android:gravity="center"
            android:text="@string/lblPtsVacio" />

    </LinearLayout>

As you can see both layouts get the same value for the layout_width attribute (match_parent). Inside both layouts I have the same number of elements (8 TextView). Each TextView has the same weight except the first one, that has a weight of 8.

If both layouts are the same (only differ the label on the TextViews) why do they have different sizes?

double-beep
  • 5,031
  • 17
  • 33
  • 41
a.ras2002
  • 385
  • 2
  • 7
  • 21

5 Answers5

2

Try this way,hope this will help you to solve your problem.

<LinearLayout 
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:orientation="vertical" >

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content">

        <TextView
            android:layout_width="0dp"
            android:layout_height="wrap_content"
            android:layout_weight="8"
            android:gravity="center"
            android:text="@string/lblPais" />

        <TextView
            android:layout_width="0dp"
            android:layout_height="wrap_content"
            android:layout_weight="1"
            android:gravity="center"
            android:text="@string/lblJ" />

        <TextView
            android:layout_width="0dp"
            android:layout_height="wrap_content"
            android:layout_weight="1"
            android:gravity="center"
            android:text="@string/lblG" />

        <TextView
            android:layout_width="0dp"
            android:layout_height="wrap_content"
            android:layout_weight="1"
            android:gravity="center"
            android:text="@string/lblP" />

        <TextView
            android:layout_width="0dp"
            android:layout_height="wrap_content"
            android:layout_weight="1"
            android:gravity="center"
            android:text="@string/lblPF" />

        <TextView
            android:layout_width="0dp"
            android:layout_height="wrap_content"
            android:layout_weight="1"
            android:gravity="center"
            android:text="@string/lblPC" />

        <TextView
            android:layout_width="0dp"
            android:layout_height="wrap_content"
            android:layout_weight="1"
            android:gravity="center"
            android:text="@string/lblDif" />

        <TextView
            android:layout_width="0dp"
            android:layout_height="wrap_content"
            android:layout_weight="1"
            android:gravity="center"
            android:text="@string/lblPuntos" />

    </LinearLayout>
    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content">

        <TextView
            android:id="@+id/lblPais1"
            android:layout_width="0dp"
            android:layout_height="wrap_content"
            android:layout_weight="8"
            android:gravity="center"
            android:text="@string/lblPais" />

        <TextView
            android:id="@+id/lblJ1"
            android:layout_width="0dp"
            android:layout_height="wrap_content"
            android:layout_weight="1"
            android:gravity="center"
            android:text="@string/lbl0" />

        <TextView
            android:id="@+id/lblG1"
            android:layout_width="0dp"
            android:layout_height="wrap_content"
            android:layout_weight="1"
            android:gravity="center"
            android:text="@string/lbl0" />

        <TextView
            android:id="@+id/lblP1"
            android:layout_width="0dp"
            android:layout_height="wrap_content"
            android:layout_weight="1"
            android:gravity="center"
            android:text="@string/lbl0" />

        <TextView
            android:id="@+id/lblPF1"
            android:layout_width="0dp"
            android:layout_height="wrap_content"
            android:layout_weight="1"
            android:gravity="center"
            android:text="@string/lbl0" />

        <TextView
            android:id="@+id/lblPC"
            android:layout_width="0dp"
            android:layout_height="wrap_content"
            android:layout_weight="1"
            android:gravity="center"
            android:text="@string/lbl0" />

        <TextView
            android:id="@+id/lblDif1"
            android:layout_width="0dp"
            android:layout_height="wrap_content"
            android:layout_weight="1"
            android:gravity="center"
            android:text="@string/lblPtsVacio" />

        <TextView
            android:id="@+id/lblPuntos1"
            android:layout_width="0dp"
            android:layout_height="wrap_content"
            android:layout_weight="1"
            android:gravity="center"
            android:text="@string/lblPtsVacio" />

    </LinearLayout>
</LinearLayout>
Haresh Chhelana
  • 24,720
  • 5
  • 57
  • 67
  • Thanks for the solution! Putting the widht of all the TextViews to 0dip (as Eclipse says that is better to use that rather than 0dp) solve my problem – a.ras2002 Jul 17 '14 at 07:50
1

if you want all layout to be same as your weight

your orientation is vertical so change...

android:layout_height="wrap_content"

to

android:layout_height="0dp"

In all TextView

Pragnesh Ghoda シ
  • 8,318
  • 3
  • 25
  • 40
1

You havent given android:weightSum="15" in first linear layout.

Rujul1993
  • 1,631
  • 2
  • 10
  • 10
0

You have to add andoid:weightSum="15" on the first parent layout and everything should fall into place.

Si8
  • 9,141
  • 22
  • 109
  • 221
0

Make your parent linear layout height as android:layout_height="match_parent"

Sumit
  • 152
  • 2
  • 11
  • This post is being automatically flagged as low quality because it is so short. Would you mind expanding it by adding some text to explain how it solves the problem? – gung - Reinstate Monica Jul 16 '14 at 13:40