LinearLayout Weights


Last Updated:

  1. Mark.D

    Mark.D Member This Topic's Starter

    Joined:
    Jul 4, 2010
    Messages:
    6
    Likes Received:
    1
    Hey guys :)
    First post here and I'd like to say I'm a complete beginner at android development (got a lot of programming experience though)

    I was going through Google's own 'Dev Guide' looking at LinearLayouts and started playing with the "android:layout_weight" property when I noticed something odd. Heres my main.xml

    PHP:
    1.  
    2. <?xml version="1.0" encoding="utf-8"?>
    3. <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    4.     android:orientation="vertical"
    5.     android:layout_width="fill_parent"
    6.     android:layout_height="fill_parent"
    7.     >  
    8.     <LinearLayout
    9.         android:orientation="horizontal"
    10.         android:layout_width="fill_parent"
    11.         android:layout_height="fill_parent"
    12.         android:layout_weight="1"
    13.         >          
    14.         <TextView
    15.             android:background="#aa0000"
    16.             android:layout_width="wrap_content"
    17.             android:layout_height="fill_parent"
    18.             android:layout_weight="1"
    19.             />
    20.         <TextView
    21.             android:background="#00aa00"
    22.             android:layout_width="wrap_content"
    23.             android:layout_height="fill_parent"
    24.             android:layout_weight="1"
    25.             />
    26.     </LinearLayout>
    27.    
    28.     <LinearLayout
    29.         android:orientation="vertical"
    30.         android:layout_width="fill_parent"
    31.         android:layout_height="fill_parent"
    32.         android:layout_weight="1"
    33.         >  
    34.         <TextView
    35.             android:layout_height="wrap_content"
    36.             android:layout_width="fill_parent"
    37.             android:layout_weight="1"
    38.             />
    39.         <TextView
    40.             android:background="#FFFFFF"
    41.             android:layout_height="wrap_content"
    42.             android:layout_width="fill_parent"
    43.             android:layout_weight="1"
    44.             />
    45.     </LinearLayout>
    46. </LinearLayout>
    47.  
    If I increase the "android:layout_weight" property on the TextView objects (is this what you call them? :confused:), they expand and push the others accordingly as I would expect, however it seemed to be the total opposite when I increased the weights of the LinearLayout objects. The increased LinearLayout got smaller and was pushed by the other(s). Is this behaviour working as intended or do I have something mixed up?

    This I know will have a ridiculously simple answer, but I gotta start somewhere :)

    Thanks in advance.
     

    Advertisement
  2. cp1

    cp1 Well-Known Member

    Joined:
    Apr 30, 2010
    Messages:
    375
    Likes Received:
    35
    Both of your linear layouts have fill parent in both width and height, so I'm not sure how android is calculating what their h/w should be.
     

Share This Page

Loading...