处理TableLayout的有效方法?

Effective Way to Deal With TableLayout?

我的 table 布局有问题。我的 table 由 24 行和 8 列组成。在 tablet 中,它看起来漂亮又合身。但是在 phone 中,它看起来很糟糕。

有没有办法处理 Table 布局,使其在 phone 中看起来不错?使用任何图书馆或任何建议?

已更新:

在 Nexus 7 中 tablet。界面还可以。

enter image description here

在 Nexus 5x 中。这是不好的。该值只会显示一半。

enter image description here

代码很长。注意:这不是我的代码。我刚找到一份 android 开发人员的工作,需要改进他们的代码。我将只显示 1 行和 1 列。

 <TableLayout
            android:id="@+id/tabla_cuerpo1b"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_marginLeft="5dp"
            android:layout_marginTop="5dp"
            android:gravity="center">

            <TableRow
                android:id="@+id/tbrl"
                android:layout_width="match_parent"
                android:layout_height="0dp"
                android:layout_weight="1"
                android:gravity="center">

                <FrameLayout
                    android:layout_width="0dp"
                    android:layout_height="wrap_content"
                    android:layout_weight="2"

                    android:paddingLeft="5dp"
                    android:paddingRight="5dp">

                    <TextView
                        android:id="@+id/mainLabel"
                        android:layout_width="wrap_content"
                        android:layout_height="wrap_content"
                        android:layout_gravity="top|right"
                        android:text="TPS"
                        android:textAppearance="?android:attr/textAppearanceLarge" />

                    <TextView
                        android:id="@+id/statView"
                        android:layout_width="wrap_content"
                        android:layout_height="wrap_content"
                        android:layout_gravity="bottom|left"
                        android:text="RPM"
                        android:textAppearance="?android:attr/textAppearanceLarge" />

                    <ImageView
                        android:id="@+id/imageView1"
                        android:layout_width="wrap_content"
                        android:layout_height="wrap_content"
                        android:layout_gravity="center"
                         />

                    <TextView
                        android:id="@+id/speedL"
                        android:layout_width="wrap_content"
                        android:layout_height="wrap_content"
                        android:text="\n"
                        android:textAppearance="?android:attr/textAppearanceLarge"
                        android:visibility="invisible" />
                </FrameLayout>

                <TextView
                    android:id="@+id/ld1"
                    android:layout_width="0dp"
                    android:layout_height="match_parent"
                    android:layout_weight="1"

                    android:gravity="center"

                    android:text="10%"
                    android:textAppearance="?android:attr/textAppearanceLarge" />

                <TextView
                    android:id="@+id/ld2"
                    android:layout_width="0dp"
                    android:layout_height="match_parent"
                    android:layout_weight="1"

                    android:gravity="center"

                    android:text="20%"
                    android:textAppearance="?android:attr/textAppearanceLarge" />

                <TextView
                    android:id="@+id/ld3"
                    android:layout_width="0dp"
                    android:layout_height="match_parent"
                    android:layout_weight="1"

                    android:gravity="center"

                    android:text="30%"
                    android:textAppearance="?android:attr/textAppearanceLarge" />

                <TextView
                    android:id="@+id/ld4"
                    android:layout_width="0dp"
                    android:layout_height="match_parent"
                    android:layout_weight="1"

                    android:gravity="center"

                    android:text="40%"
                    android:textAppearance="?android:attr/textAppearanceLarge" />

                <TextView
                    android:id="@+id/ld5"
                    android:layout_width="0dp"
                    android:layout_height="match_parent"
                    android:layout_weight="1"

                    android:gravity="center"

                    android:text="50%"
                    android:textAppearance="?android:attr/textAppearanceLarge" />

                <TextView
                    android:id="@+id/ld6"
                    android:layout_width="0dp"
                    android:layout_height="match_parent"
                    android:layout_weight="1"

                    android:gravity="center"

                    android:text="60%"
                    android:textAppearance="?android:attr/textAppearanceLarge" />

                <TextView
                    android:id="@+id/ld7"
                    android:layout_width="0dp"
                    android:layout_height="match_parent"
                    android:layout_weight="1"

                    android:gravity="center"

                    android:text="70%"
                    android:textAppearance="?android:attr/textAppearanceLarge" />

                <TextView
                    android:id="@+id/ld8"
                    android:layout_width="0dp"
                    android:layout_height="match_parent"
                    android:layout_weight="1"

                    android:gravity="center"

                    android:text="80%"
                    android:textAppearance="?android:attr/textAppearanceLarge" />
            </TableRow>

尝试阅读此内容 documentation。这是 android 的完整文档。仔细阅读 WeightWeightSumWeight 使布局更具响应性并在屏幕上使用相同数量的 space。

例如

注意这是一个LinearLayout示例

如果我想添加两个 LinearLayout 像这样:

代码如下:

<?xml version="1.0" encoding="utf-8"?>

<LinearLayout
    android:layout_width="match_parent"
    android:layout_height="100dp"
    android:layout_margin="50dp"
    android:background="@drawable/rounded_circle"
    android:weightSum="2"
    android:orientation="horizontal">

    <LinearLayout
        android:layout_margin="10dp"
        android:layout_width="0dp"
        android:layout_height="match_parent"
        android:layout_weight="1"
        android:background="@drawable/rounded_circle"
        android:gravity="center"
        >

        <TextView
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="1"/>


    </LinearLayout>

    <LinearLayout
        android:layout_margin="10dp"
        android:layout_width="0dp"
        android:layout_height="match_parent"
        android:layout_weight="1"
        android:background="@drawable/rounded_circle"
        android:gravity="center"
        >

        <TextView
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="2"/>

    </LinearLayout>


</LinearLayout>

我想我现在已经找到了最好的解决方案。解决办法是使用SCROLLVIEW,以便在5寸屏幕上使用。

谢谢。

您可以在滚动视图中使用约束布局,这将帮助您简化布局层次结构并显着提高性能。