android ограничение ограничений, возможно ли установить mmaxWidth в процентах - PullRequest
1 голос
/ 22 марта 2020

Имея три textView, размер контента варьируется. Хотите показать многоточие, если содержимое слишком большое.

|[aaa][bbb][ccc]           |
|[aaaaaaa...][bbbbbb.][ccc]| 
|[aaa][bbbbbb.......][c...]|   
|[aaaa...][bbbb...][ccc...]|          

не может найти решение, использующее для него constraintLayout. Этот не нужен, но если он может установить [a] с maxWidth в процентах от родительской ширины, так что он может оставить некоторую ширину для [b] и [c]

что-то нравится (но его не существует)

android:maxWidth="50%"

Любое предложение? Что такое

<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.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"
    android:background="@android:color/white"
    android:padding="22dp">

    <TextView
        android:id="@+id/greenTextView"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_marginEnd="8dp"
        android:ellipsize="end"
        android:maxLines="1"
        android:textColor="@android:color/holo_green_dark"
        app:layout_constraintEnd_toStartOf="@id/blueTextView"
        app:layout_constraintHorizontal_chainStyle="packed"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintTop_toTopOf="parent"
        tools:text="Firdsfgsdfgasdsdfasdsdfsds" />

    <TextView
        android:id="@+id/blueTextView"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_marginEnd="8dp"
        android:ellipsize="end"
        android:maxLines="1"
        android:textColor="@android:color/holo_blue_dark"

        app:layout_constrainedWidth="true"

        app:layout_constraintBaseline_toBaselineOf="@id/greenTextView"
        app:layout_constraintEnd_toStartOf="@id/orangetextView"
        app:layout_constraintStart_toEndOf="@id/greenTextView"
        app:layout_constraintTop_toTopOf="parent"
        tools:text="Secoasdfsdfsdfsdfsdf.." />

    <TextView
        android:id="@+id/orangetextView"
        android:layout_width="0dp"
        android:layout_height="wrap_content"
        android:layout_marginEnd="8dp"
        android:ellipsize="end"
        android:maxLines="1"
        android:textColor="@android:color/holo_orange_dark"
        app:layout_constraintBaseline_toBaselineOf="@id/blueTextView"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintStart_toEndOf="@id/blueTextView"
        tools:text="Third Very Long Text 123456789" />
</androidx.constraintlayout.widget.ConstraintLayout>

1 Ответ

0 голосов
/ 28 марта 2020

Это простой обходной путь, для достижения логического значения c в процентах по ширине мы можем использовать две вертикальные Guideline, которые могут разбить экран на три части:

Это простой код I написал для вас:

<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.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"
    android:background="@android:color/white"
    android:padding="22dp">

    <TextView
        android:id="@+id/greenTextView"
        android:layout_width="0dp"
        android:layout_height="wrap_content"
        android:ellipsize="end"
        android:maxLines="1"
        android:textColor="@android:color/holo_green_dark"
        app:layout_constraintEnd_toStartOf="@+id/guideline"
        app:layout_constraintHorizontal_chainStyle="packed"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintTop_toTopOf="parent"
        tools:text="Firdsfgsdfgasdsdfasdsdfsds" />

    <TextView
        android:id="@+id/blueTextView"
        android:layout_width="0dp"
        android:layout_height="wrap_content"
        android:layout_marginStart="8dp"
        android:ellipsize="end"
        android:maxLines="1"
        android:textColor="@android:color/holo_blue_dark"
        app:layout_constrainedWidth="true"
        app:layout_constraintBaseline_toBaselineOf="@id/greenTextView"
        app:layout_constraintEnd_toStartOf="@+id/guideline3"
        app:layout_constraintStart_toStartOf="@+id/guideline"
        app:layout_constraintTop_toTopOf="parent"
        tools:text="Secoasdfsdfsdfsdfsdf.." />

    <TextView
        android:id="@+id/orangetextView"
        android:layout_width="0dp"
        android:layout_height="wrap_content"
        android:layout_marginStart="8dp"
        android:layout_marginEnd="8dp"
        android:ellipsize="end"
        android:maxLines="1"
        android:textColor="@android:color/holo_orange_dark"
        app:layout_constraintBaseline_toBaselineOf="@id/blueTextView"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintStart_toStartOf="@+id/guideline3"
        tools:text="Third Very Long Text 123456789" />

    <androidx.constraintlayout.widget.Guideline
        android:id="@+id/guideline"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:orientation="vertical"
        app:layout_constraintGuide_percent="0.33" />

    <androidx.constraintlayout.widget.Guideline
        android:id="@+id/guideline3"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:orientation="vertical"
        app:layout_constraintGuide_percent="0.66" />
</androidx.constraintlayout.widget.ConstraintLayout>

Вы можете настроить пробелы по margins, любые комментарии или модификации, пожалуйста, скажите мне, ура

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