1. Check out our companion app, Forums for Android! Download from Google Play

LinearLayout Weights

Discussion in 'Application Development' started by Mark.D, Jul 4, 2010.

  1. Mark.D

    Mark.D Member
    Thread Starter
    6

    Jul 4, 2010
    6
    1
    6
    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? :thinking:), 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
    53

    Apr 30, 2010
    375
    35
    53
    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...