2

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

Emre Erkan
  • 8,433
  • 3
  • 48
  • 53
citizen conn
  • 15,300
  • 3
  • 58
  • 80

1 Answers1

3

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

Glendon Trullinger
  • 4,052
  • 1
  • 28
  • 35
  • Yes, indeed. I don't understand why it worked, but it worked. Can you explain? – citizen conn Jun 05 '11 at 23:34
  • 1
    Say you have a parent view with various child views. If you set each child view to wrap_content and then specify layout weights, each view will expand the fill the remaining white space in the proportion of its weight to the total weight. Thus, if you only have one view (the ViewFlipper) inside the parent view (LinearLayout), setting a layout weight will cause it to fill the rest of the white space. That's why layout weight works; as for why fill_parent on the width didn't work in the first place, I'm not really sure, but it's likely an issue with measuring views that haven't yet been drawn. – Glendon Trullinger Jun 05 '11 at 23:39
  • Thank you. Still baffled as to why fill_parent didn't work in the first place - like you said - but I understand now why adding layout_weight adds extra insurance that it will fill all the content. – citizen conn Jun 06 '11 at 00:10