开发者

Android: tablerow disappears?

I have a <TableLayout> with two <TableRow>s. The first row contains two buttons (this works fine), and the second row contains a <FrameLayout> that contains an <ImageView>. My problem is, the second TableRow (and FrameLayout) do not appear until I load an image into the ImageView. I want the FrameLayout to be visible (with its background color) at all times.

I have used android:layout_width="match_parent" and android:layout_height="match_parent" in the <ImageView> and <FrameLayout>, but it does not seem to help.

Here is the layout xml:

<TableLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:paddingTop="5dp"
    android:stretchColumns="1">
    <TableRow>
        <Button
            android:id="@+id/buttonLoadPhoto"
            android:text="Load..."
            android:textSize="20sp"
            android:layout_width="0dp"
            android:layout_height="wrap_content"
            android:layout_weight="1" />
        <Button
            android:id="@+id/buttonPrintPhoto"
            android:text="Print..."
            android:textSize="20sp"
            android:layout_width="0dp"
            android:layout_height="wrap_content"
            android:layout_weight="1" />
    </TableRow>
    <TableRow
        android:background="#FF4422">
        <FrameLayout
            android:id="@+id/frameLayoutPhoto"
            xmlns:android="http://schemas.android.com/apk/res/android"
   开发者_如何学C         android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:background="#303030">
            <ImageView
                android:id="@+id/imageViewPhoto"
                android:layout_width="match_parent"
                android:layout_height="match_parent"
                android:scaleType="matrix">
            </ImageView>
        </FrameLayout>
    </TableRow>
</TableLayout>

Note 1: I have included a background color for the offending <TableRow> just so I could narrow down the problem to the TableRow and not the ImageView (the TableRow's background color does not show up).

Note 2: This is the layout for an Activity that is loaded into a <TabHost>'s <FrameLayout>, in case that matters.

Note 3: I am targeting Android 2.2, and I am using a Xoom to test.

Essentially, I want the <FrameLayout> to take up the remaining space in the tab. Is there an alternative way to do this?

Thanks!


The documentation states that layout_height should be WRAP_CONTENT and width should be MATCH_PARENT, and that you do not need to specify these since it will enforce it anyway. I'm not sure if you added those in as you were trying to debug it or not.

Edit (This line is incorrect, but remains here as it is mentioned in the comments):You can also try setting a height for the TableRow, since none is provided and the content inside of it does not have a height until an image is there.


I found an alternative solution using <LinearLayout>s instead:

<LinearLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical"
    android:paddingTop="5dp">
    <LinearLayout
        xmlns:android="http://schemas.android.com/apk/res/android"
        android:layout_width="match_parent"
        android:layout_height="wrap_content">
        <Button
            android:id="@+id/buttonLoadPhoto"
            android:text="Load..."
            android:textSize="20sp"
            android:layout_width="0dp"
            android:layout_height="wrap_content"
            android:layout_weight="1" />
        <Button
            android:id="@+id/buttonPrintPhoto"
            android:text="Print..."
            android:textSize="20sp"
            android:layout_width="0dp"
            android:layout_height="wrap_content"
            android:layout_weight="1" />
    </LinearLayout>
    <FrameLayout
        android:id="@+id/frameLayoutPhoto"
        xmlns:android="http://schemas.android.com/apk/res/android"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:background="#303030">
        <ImageView
            android:id="@+id/imageViewPhoto"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:scaleType="matrix">
        </ImageView>
    </FrameLayout>
</LinearLayout>
0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜