0

我的应用程序使用 TableLayout 向用户显示一些数据。当我在 API 级别 11 或更高级别的设备(或 AVD)上运行该应用程序时,表格会按预期完美显示。

api 11 级截图

但是,一旦我使用 API 级别为 10 或更低的 AVD,TableView 就不再显示边距,也不能正确执行android:layout_width="wrap_content"-tag。

api 8级截图

有谁知道,为什么会这样,我该如何解决?边距不是第一要务(它只是看起来很难看),但内容包装是:由于表格没有按预期包装整个内容,用户将无法获得他应该获得的所有信息!

这是我的 XML:

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    tools:context=".EvalActivity" >       

    <ScrollView
        android:id="@+id/scrollViewGeneral"
        android:layout_width="wrap_content"
        android:layout_height="match_parent"        
        android:layout_alignParentLeft="true"
        android:layout_alignParentTop="true"
        android:layout_marginLeft="10dp"
        android:layout_marginRight="10dp"
        android:layout_marginTop="10dp"        
        android:layout_marginBottom="10dp"          
        android:background="@drawable/border_surrounded" >

        <TableLayout
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_margin="10dp" >

            <TableRow
                android:layout_width="wrap_content"
                android:layout_height="wrap_content" >

                <TextView
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:layout_marginRight="@dimen/margin_EvalTableRight"
                    android:layout_marginBottom="@dimen/margin_EvalTableBottom"
                    android:text="@string/str_EvalNumberOfProblems"
                    android:textAppearance="?android:attr/textAppearanceMedium" />

                <TextView
                    android:id="@+id/lblProblemsCount"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:gravity="right"
                    android:text="@string/lbl_OutputDummyString"
                    android:textAppearance="?android:attr/textAppearanceMedium" />

            </TableRow>

            <TableRow
                android:layout_width="wrap_content"
                android:layout_height="wrap_content" >

                <TextView
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:layout_marginRight="@dimen/margin_EvalTableRight"
                    android:layout_marginBottom="@dimen/margin_EvalTableBottom"
                    android:text="@string/str_EvalCorrectSolutions"
                    android:textAppearance="?android:attr/textAppearanceMedium" />

                <TextView
                    android:id="@+id/lblCorrectSolutions"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:gravity="right"
                    android:text="@string/lbl_OutputDummyString"
                    android:textAppearance="?android:attr/textAppearanceMedium" />

            </TableRow>

            <TableRow
                android:layout_width="wrap_content"
                android:layout_height="wrap_content" >

                <TextView
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:layout_marginRight="@dimen/margin_EvalTableRight"
                    android:layout_marginBottom="@dimen/margin_EvalTableBottomBreak"
                    android:text="@string/str_EvalWrongSolutions"
                    android:textAppearance="?android:attr/textAppearanceMedium" />

                <TextView
                    android:id="@+id/lblWrongSolutions"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:gravity="right"
                    android:text="@string/lbl_OutputDummyString"
                    android:textAppearance="?android:attr/textAppearanceMedium" />

            </TableRow>

            <TableRow
                android:layout_width="wrap_content"
                android:layout_height="wrap_content" >

                <TextView
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:layout_marginRight="@dimen/margin_EvalTableRight"
                    android:layout_marginBottom="@dimen/margin_EvalTableBottom"
                    android:text="@string/str_EvalDuration"
                    android:textAppearance="?android:attr/textAppearanceMedium" />

                <TextView
                    android:id="@+id/lblDuration"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:gravity="right"
                    android:text="@string/lbl_OutputDummyString"
                    android:textAppearance="?android:attr/textAppearanceMedium" />

            </TableRow>

            <TableRow
                android:layout_width="wrap_content"
                android:layout_height="wrap_content" >

                <TextView
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:layout_marginRight="@dimen/margin_EvalTableRight"
                    android:layout_marginBottom="@dimen/margin_EvalTableBottom"
                    android:text="@string/str_EvalAverageDuration"
                    android:textAppearance="?android:attr/textAppearanceMedium" />

                <TextView
                    android:id="@+id/lblAverageDuration"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:gravity="right"
                    android:text="@string/lbl_OutputDummyString"
                    android:textAppearance="?android:attr/textAppearanceMedium" />

            </TableRow>

            <TableRow
                android:layout_width="wrap_content"
                android:layout_height="wrap_content" >

                <TextView
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:layout_marginRight="@dimen/margin_EvalTableRight"
                    android:layout_marginBottom="@dimen/margin_EvalTableBottom"
                    android:text="@string/str_EvalShortestDuration"
                    android:textAppearance="?android:attr/textAppearanceMedium" />

                <TextView
                    android:id="@+id/lblShortestDuration"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:gravity="right"
                    android:text="@string/lbl_OutputDummyString"
                    android:textAppearance="?android:attr/textAppearanceMedium" />

            </TableRow>

            <TableRow
                android:layout_width="wrap_content"
                android:layout_height="wrap_content" >

                <TextView
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:layout_marginRight="@dimen/margin_EvalTableRight"
                    android:layout_marginBottom="@dimen/margin_EvalTableBottomBreak"
                    android:text="@string/str_EvalLongestDuration"
                    android:textAppearance="?android:attr/textAppearanceMedium" />

                <TextView
                    android:id="@+id/lblLongestDuration"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:gravity="right"
                    android:text="@string/lbl_OutputDummyString"
                    android:textAppearance="?android:attr/textAppearanceMedium" />

            </TableRow>

            <TableRow
                android:layout_width="wrap_content"
                android:layout_height="wrap_content" >

                <TextView
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:layout_marginRight="@dimen/margin_EvalTableRight"
                    android:layout_marginBottom="@dimen/margin_EvalTableBottom"
                    android:text="@string/str_EvalAddition"
                    android:textAppearance="?android:attr/textAppearanceMedium" />

                <TextView
                    android:id="@+id/lblAddition"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:gravity="right"
                    android:text="@string/lbl_OutputDummyString"
                    android:textAppearance="?android:attr/textAppearanceMedium" />

            </TableRow>

            <TableRow
                android:layout_width="wrap_content"
                android:layout_height="wrap_content" >

                <TextView
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:layout_marginRight="@dimen/margin_EvalTableRight"
                    android:layout_marginBottom="@dimen/margin_EvalTableBottom"
                    android:text="@string/str_EvalSubtraction"
                    android:textAppearance="?android:attr/textAppearanceMedium" />

                <TextView
                    android:id="@+id/lblSubtraction"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:gravity="right"
                    android:text="@string/lbl_OutputDummyString"
                    android:textAppearance="?android:attr/textAppearanceMedium" />

            </TableRow>

            <TableRow
                android:layout_width="wrap_content"
                android:layout_height="wrap_content" >

                <TextView
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:layout_marginRight="@dimen/margin_EvalTableRight"
                    android:layout_marginBottom="@dimen/margin_EvalTableBottom"
                    android:text="@string/str_EvalMultiplication"
                    android:textAppearance="?android:attr/textAppearanceMedium" />

                <TextView
                    android:id="@+id/lblMultiplication"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:gravity="right"
                    android:text="@string/lbl_OutputDummyString"
                    android:textAppearance="?android:attr/textAppearanceMedium" />

            </TableRow>

            <TableRow
                android:layout_width="wrap_content"
                android:layout_height="wrap_content" >

                <TextView
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:layout_marginRight="@dimen/margin_EvalTableRight"
                    android:layout_marginBottom="@dimen/margin_EvalTableBottom"
                    android:text="@string/str_EvalDivision"
                    android:textAppearance="?android:attr/textAppearanceMedium" />

                <TextView
                    android:id="@+id/lblDivision"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:gravity="right"
                    android:text="@string/lbl_OutputDummyString"
                    android:textAppearance="?android:attr/textAppearanceMedium" />

            </TableRow>

            <TableRow
                android:layout_width="wrap_content"
                android:layout_height="wrap_content" >

                <TextView
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:layout_marginRight="@dimen/margin_EvalTableRight"
                    android:layout_marginBottom="@dimen/margin_EvalTableBottom"
                    android:text="@string/str_EvalPower"
                    android:textAppearance="?android:attr/textAppearanceMedium" />

                <TextView
                    android:id="@+id/lblPower"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:gravity="right"
                    android:text="@string/lbl_OutputDummyString"
                    android:textAppearance="?android:attr/textAppearanceMedium" />

            </TableRow>

            <TableRow
                android:layout_width="wrap_content"
                android:layout_height="wrap_content" >

                <TextView
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:layout_marginRight="@dimen/margin_EvalTableRight"
                    android:layout_marginBottom="@dimen/margin_EvalTableBottom"
                    android:text="@string/str_EvalPercent"
                    android:textAppearance="?android:attr/textAppearanceMedium" />

                <TextView
                    android:id="@+id/lblPercent"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:gravity="right"
                    android:text="@string/lbl_OutputDummyString"
                    android:textAppearance="?android:attr/textAppearanceMedium" />

            </TableRow>
        </TableLayout>
    </ScrollView>    

    <ScrollView
        android:id="@+id/scrollViewTable"
        android:layout_width="wrap_content"
        android:layout_height="match_parent"        
        android:layout_alignParentRight="true"
        android:layout_toRightOf="@+id/scrollViewGeneral"
        android:layout_alignParentTop="true"
        android:layout_marginLeft="0dp"
        android:layout_marginRight="10dp"
        android:layout_marginTop="10dp"        
        android:layout_marginBottom="10dp"          
        android:background="@drawable/border_surrounded" >

        <TableLayout
            android:id="@+id/tableViewTable"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_margin="10dp" >

            <!-- 
            CONTENT GENERATED PROGRAMATICALLY! 
            -->          
        </TableLayout>

    </ScrollView>
 </RelativeLayout>
4

1 回答 1

0

要解决此问题,您需要在表格布局上设置重力。由于您在所有方面都使用边距,因此您可能需要android:gravity="center". 出于某种原因,如果您没有为TableLayout.

于 2013-05-14T02:35:12.673 回答