layout_weight in LinearLayout is driving me nuts. I've read reams of similar question on StackOverflow and the web but none address my problem. I've copied multiple samples I've encountered but still no joy. My layout (below) is very simple
I've tried multiple values for button widths (fill_parent, wrap_content, 0dp, etc). Also tried explicitly setting weightSum=5.0 in LinearLayout -- all width the same (bad) result.
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="horizontal"
>
<!-- TRIED BUTTON WIDTHS OF fill_parent, wrap_content, 0dp - SAME RESULT! -->
<!-- TRIED weightSum=5.0 FOR LinearLayout - SAME RESUT! -->
<Button
android:text="North"
android:id="@+id/up"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1.0"
/>
<Button
android:text="South"
android:id="@+id/down"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1.0"
/>
<Button
android:text="West"
android:id="@+id/left"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1.0"
/>
<Button
android:text="East"
android:id="@+id/right"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1.0"
/>
<Button
android:text="Exit"
android:id="@+id/done"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1.0"
/>
</LinearLayout>
Don't know if it's related but this problem appeared shortly after my phone got an OTA update from KitKat to Lollipop. Also, I use this layout in a custom Dialog not an Activity as shown below.
Dlg = new Dialog( Ctx );
Dlg.setContentView(R.layout.nudge );
Dlg.setTitle( "Direction" );
Dlg.setCancelable(false);
The first image below shows the problem: the buttons don't fill the layout and text wraps.
Strangely, the layout looks just fine in the Eclipse Graphical Layout (second image).
I've spent days on this problem without joy. Please help!