「Android」TextViewの略語を使用すると、他のビューは消えます

幅=0 dpを左側TextViewのサムネイルに設定した場合、右側TextViewは左側TextViewと一致しません.

これは、width領域を0 dpに設定して略語処理を行う場合、widthが固定されるためである.
<?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=".MainActivity">
<TextView
android:id="@+id/tv_content"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:text="undicesimo dodicesimo tredicesimo quattoridicesimo quindicesimo"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintEnd_toStartOf="@id/tv_end"
app:layout_constraintHorizontal_bias="0.0"
app:layout_constraintTop_toTopOf="parent"
android:ellipsize="end"
android:maxLines="1"/>
<TextView
android:id="@+id/tv_end"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="end text"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintEnd_toEndOf="parent"/>
</androidx.constraintlayout.widget.ConstraintLayout>

前述したように、右側のTextViewは左側のTextViewの長さに従って左に出力されますが、chainとconstraintWidth defaultは略語処理時に自分の位置を保持することを保証します.
使用します.
constraintLayout_chainStyle
すべてのビューがwidth全体に存在する必要があるため、ビューの隣に誰がいるかを示すためにチェーンを掛けなければなりません.widthを使用するため、水平ビューとビューを互いにマージする必要があるため、チェーンスタイルはpackageを使用します.
水平チェーンを掛けるには、各ビューの開始と終了が隣のビューを指す必要があります.
<?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=".MainActivity">
<TextView
android:id="@+id/tv_content"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="hi"
app:layout_constraintHorizontal_chainStyle="packed"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintEnd_toStartOf="@id/tv_end"
app:layout_constraintTop_toTopOf="parent"
android:ellipsize="end"
android:maxLines="1"/>
<TextView
android:id="@+id/tv_end"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="end text"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintStart_toEndOf="@id/tv_content"
app:layout_constraintEnd_toEndOf="parent"/>
</androidx.constraintlayout.widget.ConstraintLayout>

左側のTextView(hi)のwidthをwrap contentに変更すると、chainが正しく停止していることが求められます.
constraintWidth_default
略語TextViewのwidthはテキストの長さによって変化するため、xmlでwidth値を指定することはできません.したがって、0 dpを使用して、略語処理が可能な領域を含む最大領域を指定できます.
幅を=0 dpに設定しますが、layout constraintWidth default attrを使用して幅をビューサイズに調整します.
上のコードでは、TextView(id="tv content")のwidthを0 dpに戻します.
app:layout_constraintWidth_default="wrap"
に変更すると、widthがwrap contentの場合のパッケージが表示されます.しかし、私たちは左寄りの状態を望んでいます.
app:layout_constraintHorizontal_bias="0.0"
もう少し追加すればいいです左側TextViewで水平biasを0にして左側に貼り付けます.

略語処理を使用していない場合は両方左に貼ります略語を適用するとendtextは消えず、正常に表示されることがわかります.
完全なコード
<?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=".MainActivity">
<TextView
android:id="@+id/tv_content"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:text="undicesimo dodicesimo tredicesimo quattoridicesimo quindicesimo"
app:layout_constraintHorizontal_chainStyle="packed"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintEnd_toStartOf="@id/tv_end"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintWidth_default="wrap"
app:layout_constraintHorizontal_bias="0.0"
android:ellipsize="end"
android:maxLines="1"/>
<TextView
android:id="@+id/tv_end"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="end text"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintStart_toEndOf="@id/tv_content"
app:layout_constraintEnd_toEndOf="parent"/>
</androidx.constraintlayout.widget.ConstraintLayout>
リファレンス
Reference
この問題について(「Android」TextViewの略語を使用すると、他のビューは消えます), 我々は、より多くの情報をここで見つけました https://velog.io/@deepblue/TextView-말줄임-적용될-경우-다른-View가-사라지는-문제テキストは自由に共有またはコピーできます。ただし、このドキュメントのURLは参考URLとして残しておいてください。
Collection and Share based on the CC Protocol