【发布时间】:2014-02-22 17:03:18
【问题描述】:
我正在尝试在 android 中创建一个应用程序,其主要活动具有表格布局,
第一行:1 张图片(最多占用 85% 的屏幕空间)
第 2 行:3 张图片(最多占用 10% 的屏幕空间)
第 3 行:1 个表面视图(最多占用 5% 的屏幕空间)
代码:MainLayout.xml
<?xml version="1.0" encoding="utf-8"?>
<TableLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/fullscreen_content"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_gravity="center_vertical|center_horizontal"
android:background="@color/white"
android:stretchColumns="*"
android:shrinkColumns="*"
>
<TableRow
android:id="@+id/tableRow1"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="0.85"
android:gravity="top|center"
>
<ImageView
android:id="@+id/icamera"
android:scaleType="fitXY"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:src="@drawable/cam_off"
android:layout_column="0"
android:layout_span="3"
android:layout_gravity="center|top"
android:paddingTop="0sp"
android:paddingRight="0sp"
android:paddingLeft="0sp"
android:paddingBottom="0sp"
/>
</TableRow>
<TableRow
android:id="@+id/tableRow2"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="0.10"
android:gravity="bottom|center"
>
<ImageView
android:id="@+id/isetting"
android:scaleType="centerInside"
android:layout_width="wrap_content"
android:layout_height="0dp"
android:src="@drawable/settings"
android:layout_column="0"
android:layout_weight="0.30"
android:layout_gravity="left|bottom"
android:paddingTop="0sp"
android:paddingRight="0sp"
android:paddingLeft="0sp"
android:paddingBottom="0sp"
/>
<ImageView
android:id="@+id/icredits"
android:scaleType="centerInside"
android:layout_width="wrap_content"
android:layout_height="0dp"
android:src="@drawable/credits"
android:layout_gravity="center|bottom"
android:layout_column="1"
android:layout_weight="0.30"
android:paddingTop="0sp"
android:paddingRight="0sp"
android:paddingLeft="0sp"
android:paddingBottom="0sp"
/>
<ImageView
android:id="@+id/ihelp"
android:scaleType="centerInside"
android:layout_width="wrap_content"
android:layout_height="0dp"
android:src="@drawable/help"
android:layout_column="2"
android:layout_gravity="center|bottom"
android:paddingTop="0sp"
android:paddingRight="0sp"
android:paddingLeft="0sp"
android:paddingBottom="0sp"
android:layout_weight="0.30"
/>
</TableRow>
<TableRow
android:id="@+id/tableRow3"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="0.05"
android:layout_gravity="bottom"
>
<SurfaceView
android:id="@+id/surfaceView2"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_column="0"
android:layout_span="3"
android:layout_gravity="bottom"
android:background="@color/black"
android:scaleType="fitXY"
android:paddingTop="0sp"
android:paddingRight="0sp"
android:paddingLeft="0sp"
android:paddingBottom="0sp">
</SurfaceView>
</TableRow>
</TableLayout>
但是当我运行第一行的应用程序图像时,它会消失并显示:
第一行:3 张图片(最多占用 10% 的屏幕空间)
第 2 行:表面视图(最多占用 90% 的屏幕空间)
请帮帮我..
【问题讨论】:
-
您正在使用嵌套在某些图像视图中的布局权重,但未在这些图像视图中提供关联的 0dp。因此,这三个图像可能会在某些时候遇到该部分代码的问题。我还没有尝试过行中的布局权重。如果它受支持,那么我不会立即看到问题。
-
我在第二行的图像中使用了布局权重(将 raw 分成 3 个等宽的单元格),它可以毫无问题地显示。我的问题是第 1 行的图像没有显示出来。
-
我明白了,但是如果没有 0dp 而不是 wrap_content / match_parent 属性,您当前的 ImageView 组件将无法正确使用权重。
-
好的,我理解您的关注点并在我的代码中进行了更新。
-
谢谢。但同时你能找出为什么表面视图也利用第一行的空间吗?
标签: android surfaceview tablelayout