1

Имеется layout:

<android.support.constraint.ConstraintLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    android:layout_width="match_parent"
    android:layout_height="match_parent">

    <Button
        android:id="@+id/button10"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:ellipsize="end"
        android:singleLine="true"
        android:text="small text"
        app:layout_constraintLeft_toLeftOf="parent"/>

    <Button
        android:ellipsize="end"
        android:singleLine="true"
        android:id="@+id/button11"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="small text"
        app:layout_constraintRight_toRightOf="parent"/>

</android.support.constraint.ConstraintLayout>

Отображается вот так: введите сюда описание изображения Сейчас все нормально, но если заменить android:text="small text" на android:text="big teeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeext" то вьюхи будут накладываться и перекрывать друг друга.

Задача сделать так, чтобы при маленьком тексте был "wrap content", как я собственно и показывал на скрине выше, но при большом тесте - вьюхи с текстом занимали бы максимум приблизительно 40 процентов от парента по горизонтали. Ну и также чтобы текст не переносился - я делаю android:ellipsize="end" и android:singleLine="true".

Вот так должно быть (отредактировано в Фотошопе для демонстрации): введите сюда описание изображения Есть ли средства для этого в ConstraintLayout или на худой конец - тогда другими лайоутами.

1 ответ 1

1

сцепите вьюхи друг с другом, добавив к первой:

app:layout_constraintEnd_toStartOf="@+id/button11"

ко второй:

app:layout_constraintStart_toEndOf="@+id/button10"

эта строчка прижмет их к краям:

app:layout_constraintHorizontal_chainStyle="spread_inside"

ширина вьюх должна быть 0dp, тогда она будет зависеть только от constraints и не будет наложений. и можно добавить маргины у каждой вьюхи.

<android.support.constraint.ConstraintLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent">

<Button
    android:id="@+id/button10"
    android:layout_width="0dp"
    android:layout_height="wrap_content"
    android:layout_marginTop="8dp"
    android:ellipsize="end"
    android:singleLine="true"
    android:layout_marginRight="4dp"
    android:text="small textsmall textsmall text"
    app:layout_constraintEnd_toStartOf="@+id/button11"
    app:layout_constraintHorizontal_chainStyle="spread_inside"
    app:layout_constraintStart_toStartOf="parent"
    app:layout_constraintTop_toTopOf="parent" />

<Button
    android:id="@+id/button11"
    android:layout_marginLeft="4dp"
    android:layout_width="0dp"
    android:layout_height="wrap_content"
    android:layout_marginTop="8dp"
    android:ellipsize="end"
    android:singleLine="true"
    android:text="small textsmall textsmall text"
    app:layout_constraintRight_toRightOf="parent"
    app:layout_constraintStart_toEndOf="@+id/button10"
    app:layout_constraintTop_toTopOf="parent" />

Ваш ответ

By clicking “Отправить ответ”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Всё ещё ищете ответ? Посмотрите другие вопросы с метками или задайте свой вопрос.