Установите кнопки в линию и линию разрыва для соответствия различным устройствам - PullRequest
0 голосов
/ 05 июня 2019

Я хочу добавить несколько кнопок в строку и разбить ее на новую строку, когда они достигнут конца экрана:

enter image description here

ЕслиВы знаете, CSS, что мне нужно, похоже на display: inline-block rule.

Я ищу только решение XML, я хочу избегать измерения экрана и кнопок с использованием Java, чтобы программно размещать их ниже.

Это мой текущий код, следующие кнопки находятся внутри ConstraintLayout:

    <Button
        android:id="@+id/boton1"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        app:layout_constraintTop_toTopOf="parent"
        app:layout_constraintLeft_toLeftOf="parent"
        android:text="Imagen"        />
    <Button
        android:id="@+id/boton2"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        app:layout_constraintTop_toTopOf="parent"
        app:layout_constraintLeft_toRightOf="@id/boton1"
        android:text="Play"        />
    <Button
        android:id="@+id/boton3"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        app:layout_constraintTop_toTopOf="parent"
        app:layout_constraintLeft_toRightOf="@id/boton2"
        android:text="Audio"        />
    <Button
        android:id="@+id/boton4"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        app:layout_constraintTop_toTopOf="parent"
        app:layout_constraintLeft_toRightOf="@id/boton3"
        android:text="Play"
        android:onClick="playVideo"        />
    <Button
        android:id="@+id/boton5"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        app:layout_constraintTop_toTopOf="parent"
        app:layout_constraintLeft_toRightOf="@id/boton4"
        android:text="Youtube"        />
    <Button
        android:id="@+id/boton6"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        app:layout_constraintTop_toTopOf="parent"
        app:layout_constraintLeft_toRightOf="@id/boton5"
        android:text="Raw"        />

1 Ответ

1 голос
/ 05 июня 2019

Вы пробовали использовать gridLayout?

<?xml version="1.0" encoding="utf-8"?>
<GridLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:columnCount="4">

    <Button
        android:id="@+id/boton1"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="Imagen"        
        />
    <Button
        android:id="@+id/boton2"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="Play"
        />
    <Button
        android:id="@+id/boton3"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="Audio"
        />
    <Button
        android:id="@+id/boton4"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="Play"
        android:onClick="playVideo"
        />
    <Button
        android:id="@+id/boton5"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="Youtube"
        />
    <Button
        android:id="@+id/boton6"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="Raw"
        />

</GridLayout>`
...