Эффективный способ справиться с TableLayout? - PullRequest
0 голосов
/ 30 августа 2018

У меня проблема с разметкой таблицы. Моя таблица состоит из 24 строк и 8 столбцов. В планшете выглядит красиво и удобно. Но в телефоне это выглядит очень плохо.

Есть ли способ справиться с Table Layout, чтобы он выглядел красиво в телефоне? Используя какую-либо библиотеку или любое предложение?

Обновлен:

В Nexus 7 планшет. Интерфейс в порядке.

введите описание изображения здесь

В Nexus 5x. Это плохо. Значение будет показано только наполовину.

введите описание изображения здесь

Код очень длинный. ПРИМЕЧАНИЕ: это не мой код. Я просто устраиваюсь на работу на android dev и мне нужно улучшить их код. Я буду показывать только 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>

Ответы [ 3 ]

0 голосов
/ 01 сентября 2018

Я думаю, что уже нашел лучшее решение на данный момент. Решение состоит в том, чтобы использовать SCROLLVIEW, чтобы использовать в 5-дюймовом экране.

Спасибо.

0 голосов
/ 01 сентября 2018

Вы можете использовать Ограничение макета в представлении прокрутки, это поможет вам упростить иерархию макета и значительно повысить производительность.

0 голосов
/ 30 августа 2018

Попробуйте прочитать это Документация . Это полная документация Android. читай внимательно на Weight и WeightSum. Weight делает макет более отзывчивым и занимает столько же места на экране.

например

ПРИМЕЧАНИЕ это LinearLayout пример

если я хочу добавить два LinearLayout Как это:

enter image description here

вот код:

<?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>

...