layout_weight working opposite of what it should

I also just met the same problem, and the way of solving is to change:

  • width of child view to 0dp if parent LinearLayout has orientation="horizontal";

  • height of child view to 0dp if parent LinearLayout has orientation="vertical".


The issue came from the container list which had a "wrap_content" width. Changing to "match_parent" fixed the problem.

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/results_list_fragment_layout"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:orientation="vertical"
    android:paddingTop="15dp" >

    <ListView
        android:id="@+id/search_results_list"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:background="@drawable/scrollable_content_background"
        android:divider="@drawable/listview_divider"
        android:dividerHeight="1dp" >
    </ListView>

</LinearLayout>