2011-06-17 15 views
0

我有一个<TableLayout>与两个<TableRow> s。第一行包含两个按钮(工作正常),第二行包含一个<FrameLayout>,其中包含一个<ImageView>。我的问题是,第二个TableRow(和FrameLayout)不会出现,直到我加载到ImageView图像。我希望FrameLayout在任何时候都可见(以其背景色)。Android:tablerow消失?

我在<ImageView><FrameLayout>中使用了android:layout_width="match_parent"android:layout_height="match_parent",但它似乎没有帮助。

这里是布局的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" 
      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> 

注1:我已经包括了违规<TableRow>背景颜色只是这样我就可以缩小问题的TableRow,而不是ImageView(在TableRow的背景颜色不显示)。注意2:这是一个Activity的布局,加载到<TabHost><FrameLayout>,以防万一。

注3:我的目标是Android 2.2,并且我正在使用Xoom进行测试。

本质上,我想要<FrameLayout>占用选项卡中的剩余空间。有没有其他方法可以做到这一点?

谢谢!

回答

0

我发现使用<LinearLayout>!而非替代方案:

<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

documentation指出layout_height应该是WRAP_CONTENT,宽度应该是MATCH_PARENT,并且你不需要指定它们,因为它会强制执行它。我不确定是否在您尝试调试或不调试时添加了这些内容。

编辑(这条线是不正确的,但这里仍然是它在评论中提到的):你也可以尝试设置为的TableRow的高度,因为没有提供和它里面的内容不具有高度,直到有图像。

+0

我还没有加入他们,因为它说,这是没有必要的。我只是尝试在第二个“”中添加'android:layout_height =“200dp”',但它没有做任何事情。 – Ken 2011-06-17 00:56:49

+0

您的框架布局是TableRow的一个子项,您确实在上面提供的代码中设置了宽度和高度,而不必在那里。 – TomHarrigan 2011-06-17 00:59:15

+0

哦,我看到文档正在讨论TableRow的子项。删除它们没有区别 – Ken 2011-06-17 01:02:40