开发者

ViewFlipper width is wrapping its content and fill_parent is not working

开发者 https://www.devze.com 2023-03-10 19:02 出处:网络
Here is my layout XML: <?xml version=\"1.0\" encoding=\"utf-8\"?> <LinearLayout xmlns:android=\"http://schemas.android.com/apk/res/android\"

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>
      </Vi开发者_StackOverflow中文版ewFlipper>
        </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.

ViewFlipper width is wrapping its content and fill_parent is not working


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

0

精彩评论

暂无评论...
验证码 换一张
取 消