我有一个带有两个<TableRow>的<TableLayout>,第一行包含两个按钮(这很好用),第二行包含一个包含<ImageView>的<FrameLayout>。我的问题是,直到我将图像加载到ImageView中,第二个TableRow (和FrameLayout)才会出现。我希望FrameLayout始终可见(具有其背景颜色)。
我在<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:这是加载到<TabHost>的<FrameLayout>中的Activity的布局,以防万一。
注3:我的目标是Android2.2,我正在使用Xoom进行测试。
从本质上讲,我希望<FrameLayout>占据选项卡中的剩余空间。有没有其他方法可以做到这一点?
谢谢!
发布于 2011-06-18 00:36:33
我找到了使用<LinearLayout>s的替代解决方案:
<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>发布于 2011-06-17 08:50:35
documentation声明layout_height应该是WRAP_CONTENT,宽度应该是MATCH_PARENT,并且您不需要指定它们,因为它无论如何都会强制执行它们。我不确定您是否在尝试调试时添加了这些内容。
编辑(此行不正确,但仍保留在注释中提到的高度):您也可以尝试设置TableRow的高度,因为没有提供任何内容,并且其中的内容在图像出现之前没有高度。
https://stackoverflow.com/questions/6380176
复制相似问题