• After 15+ years, we've made a big change: Android Forums is now Early Bird Club. Learn more here.

Apps LinearLayout Weights

Mark.D

Lurker
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:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:orientation="vertical"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
   	>  
 	<LinearLayout
 		android:orientation="horizontal"
 		android:layout_width="fill_parent"
 		android:layout_height="fill_parent"
 		android:layout_weight="1"
 		> 			
 		<TextView
 			android:background="#aa0000"
 			android:layout_width="wrap_content"
 			android:layout_height="fill_parent"
 			android:layout_weight="1"
 			/>
 		<TextView
 			android:background="#00aa00"
 			android:layout_width="wrap_content"
 			android:layout_height="fill_parent"
 			android:layout_weight="1"
 			/>
	</LinearLayout>
	
	<LinearLayout
		android:orientation="vertical"
		android:layout_width="fill_parent"
		android:layout_height="fill_parent"
		android:layout_weight="1"
		>	
		<TextView
			android:layout_height="wrap_content"
			android:layout_width="fill_parent"
			android:layout_weight="1" 
			/>
		<TextView
			android:background="#FFFFFF"
			android:layout_height="wrap_content" 
			android:layout_width="fill_parent" 
			android:layout_weight="1"
			/>
	</LinearLayout>
</LinearLayout>

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.
 
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.
 
Back
Top Bottom