constraintlayout icon indicating copy to clipboard operation
constraintlayout copied to clipboard

TextView didn't ellipsize with layout_constraintWidth_max and layout_constraintHeight_max

Open skauss opened this issue 5 years ago • 2 comments

Hi I need a TextView with max width and height. In case the text is to long I expect dotted at the end (ellipsize="end"). This didn't work.

<?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"
    tools:context=".SecondFragment">

<TextView
        android:id="@+id/textview_second"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:ellipsize="end"

        android:text="Text sf asd fasd fas dfasd fasd fasd fas dfas dfas dfg sdfg sdfg  sdfgs fdg sdfa sdfas dfa sdfa sdfa fsaas dfas dfa sdfasd fa sdf asdf asdfasdf "

        android:maxWidth="100dp"
        android:maxHeight="100dp"
        app:layout_constraintWidth_max="100dp"
        app:layout_constraintHeight_max="100dp"
        app:layout_constraintBottom_toBottomOf="parent"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintTop_toTopOf="parent" />
</androidx.constraintlayout.widget.ConstraintLayout>

Removing maxWidth and maxHeight didn't help.

Bildschirmfoto 2021-02-09 um 08 37 10

Regards Stephan

skauss avatar Feb 09 '21 07:02 skauss

ConstraintLayout does not control the contentment of children views. It only constrains the position of views. Research ellipsis of multiline textView for a solution.

jafu888 avatar Feb 09 '21 23:02 jafu888

I encounter this situation too, i solved, but i dont know why that help In addition background follows:

<ImageButton
        android:id="@+id/fragment_dshell_state"
        android:layout_width="0dp"
        android:layout_height="0dp"
        app:layout_constraintWidth_max="350dp"
        app:layout_constraintWidth_percent="@dimen/status_width_percent"
        app:layout_constraintDimensionRatio="1"
        app:layout_constraintBottom_toBottomOf="parent"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintHorizontal_bias="0.5"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintTop_toTopOf="parent"
        app:layout_constraintVertical_bias="0.38" />

    <com.didi.it.dday.ui.widget.SelfOnDrawView
        android:layout_width="0dp"
        android:layout_height="0dp"
        android:gravity="center"
        android:padding="0dp"
        app:layout_constraintWidth_max="330dp"
        app:layout_constraintWidth_percent="0.54"
        app:layout_constraintBottom_toBottomOf="@+id/fragment_dshell_state"
        app:layout_constraintEnd_toEndOf="@+id/fragment_dshell_state"
        app:layout_constraintStart_toStartOf="@+id/fragment_dshell_state"
        app:layout_constraintTop_toTopOf="@+id/fragment_dshell_state"
        app:backWidth="7dp"
        app:backColor="#F6F6F9"
        app:progFirstColor="#FF0027EC"
        app:progStartColor="#FF6E9DFF"
        app:progWidth="7dp" />

if put SelfOnDrawView above(means write xml before) ImageButton, the app:layout_constraintWidth_max attr will not efficient

Hpbbs avatar Feb 25 '22 07:02 Hpbbs