Search code examples
androidxmllayoutviewflipperfill-parent

ViewFlipper width is wrapping its content and fill_parent is not working


Here is my layout XML:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
  xmlns:android="http://schemas.android.com/apk/res/android"
  android:layout_width="fill_parent"
  android:layout_height="fill_parent">
  <TableLayout
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:stretchColumns="true">
    <TableRow
      android:background="#FF0000">
      <ViewFlipper
        android:id="@+id/viewer_something"
        android:layout_width="fill_parent"
        android:layout_height="fill_parent">
        <LinearLayout
          android:id="@+id/view1"
          android:layout_width="fill_parent"
          android:layout_height="fill_parent"
          android:background="#CCCCCC">
          <Button
            android:id="@+id/button1"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="button one" />
        </LinearLayout>
        <LinearLayout
          android:id="@+id/view2"
          android:layout_width="fill_parent"
          android:layout_height="fill_parent"
          android:background="#FFFFFF">
          <Button
            android:id="@+id/button2"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="button two" />
        </LinearLayout>
      </ViewFlipper>
        </TableRow>
        <TableRow
          android:background="#FF0000">
          <Button
        android:id="@+id/button3"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="button three" />
        </TableRow>
      </TableLayout>
    </LinearLayout>

So in short, I have a ViewFlipper inside a TableRow. The ViewFlipper is shrinking to the size of its content, even though all of the elements have fill_parent specified. In my screenshot below, the ViewFlipper has the grey background and the TableRows have red background.

http://imgur.com/FPnsE


Solution

  • Setting android:layout_weight="1" on your ViewFlipper would work.