Android Растягивание элементов в TableLayout XML - PullRequest
0 голосов
/ 19 января 2020

В моем приложении пользователь может сам выбирать иконки уведомлений. Для этого я сделал выпадающее меню и добавил изображения значков в макет таблицы. Проблема в том, что картинки не умещаются на телефонах с маленьким экраном, а на больших экранах (на планшетах, телефонах и т. Д. c) остается много свободного места. Как я могу это исправить? Спасибо заранее!

Предварительный просмотр

  <TableLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_marginTop="16dp">
        <TableRow android:gravity="center">

            <ImageView
                android:id="@+id/img5"
                android:layout_width="50dp"
                android:layout_height="50dp"
                android:layout_gravity="center"
                android:clickable="true"
                android:focusable="true"
                android:foreground="@drawable/ripple_circular_tabs"
                android:layout_margin="8dp"
                android:src="@mipmap/ic_notifications4"
                tools:ignore="ContentDescription" />

            <ImageView
                android:id="@+id/img6"
                android:layout_width="50dp"
                android:layout_height="50dp"
                android:layout_gravity="center"
                android:layout_margin="10dp"
                android:clickable="true"
                android:focusable="true"
                android:foreground="@drawable/ripple_circular_tabs"
                android:src="@mipmap/ic_notifications10"
                tools:ignore="ContentDescription" />

            <ImageView
                android:id="@+id/img7"
                android:layout_width="50dp"
                android:layout_height="50dp"
                android:layout_gravity="center"
                android:clickable="true"
                android:focusable="true"
                android:foreground="@drawable/ripple_circular_tabs"
                android:layout_margin="10dp"
                android:src="@mipmap/ic_notifications6"
                tools:ignore="ContentDescription" />


            <ImageView
                android:id="@+id/img8"
                android:layout_width="50dp"
                android:layout_height="50dp"
                android:layout_gravity="center"
                android:layout_margin="8dp"
                android:clickable="true"
                android:focusable="true"
                android:foreground="@drawable/ripple_circular_tabs"
                android:src="@mipmap/ic_notifications7"
                tools:ignore="ContentDescription" />
        </TableRow>

    </TableLayout>

1 Ответ

2 голосов
/ 19 января 2020

Используйте android:layout_weight="1" с android:layout_width="0dp", чтобы распределить его равномерно. Проверьте ниже:

<TableRow android:gravity="center">

    <ImageView
        android:id="@+id/img5"
        android:layout_width="0dp"
        android:layout_weight="1"
        android:layout_height="50dp"
        android:layout_gravity="center"
        android:clickable="true"
        android:focusable="true"
        android:foreground="@drawable/ripple_circular_tabs"
        android:layout_margin="8dp"
        android:src="@mipmap/ic_notifications4"
        tools:ignore="ContentDescription" />

    <ImageView
        android:id="@+id/img6"
        android:layout_width="0dp"
        android:layout_weight="1"
        android:layout_height="50dp"
        android:layout_gravity="center"
        android:layout_margin="10dp"
        android:clickable="true"
        android:focusable="true"
        android:foreground="@drawable/ripple_circular_tabs"
        android:src="@mipmap/ic_notifications10"
        tools:ignore="ContentDescription" />

    <ImageView
        android:id="@+id/img7"
        android:layout_width="0dp"
        android:layout_weight="1"
        android:layout_height="50dp"
        android:layout_gravity="center"
        android:clickable="true"
        android:focusable="true"
        android:foreground="@drawable/ripple_circular_tabs"
        android:layout_margin="10dp"
        android:src="@mipmap/ic_notifications6"
        tools:ignore="ContentDescription" />


    <ImageView
        android:id="@+id/img8"
        android:layout_width="0dp"
        android:layout_weight="1"
        android:layout_height="50dp"
        android:layout_gravity="center"
        android:layout_margin="8dp"
        android:clickable="true"
        android:focusable="true"
        android:foreground="@drawable/ripple_circular_tabs"
        android:src="@mipmap/ic_notifications7"
        tools:ignore="ContentDescription" />
</TableRow>

Вывод:

  1. Портрет:

enter image description here

Пейзаж:

enter image description here

Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...