Невозможно отобразить элементы в одной строке в макете

Мой макет Android выглядит следующим образом:

<LinearLayout
            android:layout_width = "wrap_content"
            android:layout_height = "wrap_content"
            android:layout_marginTop = "2dp"
            android:orientation = "horizontal">
            <TextView
                android:id = "@+id/notification_content"
                android:layout_width = "wrap_content"
                android:layout_height = "wrap_content"
                android:layout_gravity = "left|bottom"
                android:layout_marginEnd = "1dp"
                android:ellipsize = "end"
                android:fadingEdge = "horizontal"
                android:maxLines = "4"
                android:singleLine = "false"
                android:textAppearance = "@style/Ds6"
                android:textColor = "@color/notification_ds6_secondary_text"
                tools:text = "Watched item ends in 6 minutes in "
                android:visibility = "visible"
                tools:ignore = "Deprecated"/>

            <Chronometer
                android:id = "@+id/notification_countdown"
                android:layout_width = "match_parent"
                android:layout_height = "wrap_content"
                android:layout_gravity = "bottom"
                android:gravity = "left|bottom"
                android:maxLines = "1"
                android:textAppearance = "@style/Ds6"
                android:textColor = "@color/notification_ds6_secondary_text"
                android:textSize = "@dimen/TextSizeSmall"
                android:visibility = "visible"
                tools:text = "10:02 AM" />

            <Chronometer
                android:id = "@+id/notification_countdown_60s"
                android:layout_width = "match_parent"
                android:layout_height = "wrap_content"
                android:layout_gravity = "left|bottom"
                android:gravity = "left"
                android:maxLines = "1"
                android:textColor = "@color/alert_color"
                android:textAppearance = "@style/Ds6"
                android:textSize = "@dimen/TextSizeSmall"
                android:visibility = "visible"
                tools:text = "10:02 AM" />
            <TextView
                android:id = "@+id/notification_time_expired"
                android:layout_width = "match_parent"
                android:layout_height = "wrap_content"
                android:layout_gravity = "left|bottom"
                android:text = "00:00"
                android:textColor = "@color/notification_ds6_disabled_text"
                android:textAppearance = "@style/Ds6"
                android:textSize = "@dimen/TextSizeSmall"
                android:visibility = "visible" />
            </LinearLayout>

Невозможно отобразить элементы в одной строке в макете

Я хочу, чтобы содержимое текстового представления было правильно перенесено, чтобы Хронометр № 1, Хрометер № 2 и Хронометр № 3 отображались в одной строке. Этого не происходит для более длинных текстовых строк.

Но если я уменьшу длину текстовой строки, как показано ниже, я смогу увидеть все элементы в одной строке. Как отобразить все элементы в одной строке? Я хочу, чтобы текст переносился, но два хронометра и текстовое представление № 2 должны быть в той же строке, что и первое текстовое представление.

Это будет отображаться в удаленном представлении уведомлений, поэтому я не могу использовать ConstraintLayout. Я могу использовать только FrameLayout, RelativeLayout и LinearLayout.

Невозможно отобразить элементы в одной строке в макете

1
0
142
1
Перейти к ответу Данный вопрос помечен как решенный

Ответы 1

Ответ принят как подходящий

попробуйте установить android:layout_width = "0dp" и android:layout_weight = "1" в свой notification_contentTextView

Попробуйте так

<LinearLayout
    android:layout_width = "wrap_content"
    android:layout_height = "wrap_content"
    android:layout_marginTop = "2dp"
    android:orientation = "horizontal">
    <TextView
        android:id = "@+id/notification_content"
        android:layout_width = "0dp"
        android:layout_weight = "1"
        android:layout_height = "wrap_content"
        android:layout_gravity = "left|bottom"
        android:layout_marginEnd = "1dp"
        android:ellipsize = "end"
        android:fadingEdge = "horizontal"
        android:maxLines = "4"
        android:singleLine = "false"
        android:textColor = "@color/colorPrimary"
        tools:text = "Watched item ends in 6 minutes in "
        android:visibility = "visible"
        tools:ignore = "Deprecated"/>

    <Chronometer
        android:id = "@+id/notification_countdown"
        android:layout_width = "match_parent"
        android:layout_height = "wrap_content"
        android:layout_gravity = "bottom"
        android:gravity = "left|bottom"
        android:maxLines = "1"
        android:textColor = "@color/colorPrimary"
        android:visibility = "visible"
        tools:text = "10:02 AM" />

    <Chronometer
        android:id = "@+id/notification_countdown_60s"
        android:layout_width = "match_parent"
        android:layout_height = "wrap_content"
        android:layout_gravity = "left|bottom"
        android:gravity = "left"
        android:maxLines = "1"
        android:textColor = "@color/colorAccent"
        android:visibility = "visible"
        tools:text = "10:02 AM" />
    <TextView
        android:id = "@+id/notification_time_expired"
        android:layout_width = "match_parent"
        android:layout_height = "wrap_content"
        android:layout_gravity = "left|bottom"
        android:text = "00:00"
        android:textColor = "@color/colorPrimary"
        android:visibility = "visible" />
</LinearLayout>

Другие вопросы по теме