Taglayout weight

How weight in LinearLayout works

This post is just a quick review of LinearLayout weight attribute.
Here’re a few things:

  1. If you want to divide the space equally between Views with the same weight – set 0dp as Views’ width
  2. If you set View width to wrap_content – size of the Views will depend on weight and content inside each View

hope it will help you to better understand LinearLayout weight idea.

//DL

Android 1.6: strange things happen with UI

For some reason I had the complex layout:

<LinearLayout
	android:layout_width="fill_parent"
	android:layout_height="fill_parent"
..
<FrameLayout
	android:layout_height="fill_parent"
	android:layout_width="fill_parent"
...
<ListView
	android:layout_width="fill_parent"
	android:layout_height="fill_parent"

ListView scroll worked perfectly on 1.5 and 1.6. At some point of time layout was changed to:

<LinearLayout
	android:layout_width="fill_parent"
	android:layout_height="fill_parent"
..
<FrameLayout
	android:layout_height="wrap_content"
	android:layout_weight="1"
	android:layout_width="fill_parent"
...
<ListView
	android:layout_width="fill_parent"
	android:layout_height="fill_parent"

and performance decreased dramatically on 1.6 (looks like x10 worse)… same layout works fine on 1.5. It took me a day to find this problem out.

be careful with layouts!

© 2017 Android Tales

Theme by Anders NorenUp ↑