我有兩個長文本,它們在水平方向上被限制在一起。由于這兩個文本可能相當長,所以都用省略號來截斷。以下是供參考的圖表。
| [TextView 1 ] [TextView 2] |
假設我們在兩個TextView上顯示同樣的長文本:"Hello there I am a very very long text"。我需要做的是,如果沒有足夠的空間來容納兩個TextViews,那么首先截斷右邊的TextView,然后截斷左邊的TextView。
這是我想要的結果:
| [Hello there I am a very very long text] [Hello...] |。
這是我到目前為止所嘗試的:
<androidx.constraintlayout.widget.ConstraintLayout。
xmlns:android="http://schemas.android.com/apk/res/android"/span>
xmlns:app="http://schemas.android.com/apk/res-auto"。
xmlns:tools="http://schemas.android.com/tools"。
android:layout_width="match_parent"。
android:layout_height="wrap_content"。
android:layout_marginTop="56dp"。
android:padding="20dp"/span>>
<TextView。
android:id="@ id/leftTv"/span>
android:layout_width="0dp"。
android:layout_height="wrap_content"。
android:ellipsize="end"。
android:maxLines="1"。
android:textColor="#333333"。
android:textSize="18sp"。
app:layout_constraintBottom_toBottomOf="father"
app:layout_constraintEnd_toStartOf="@ id/rightTv"
app:layout_constraintHorizontal_bias="0.0"
app:layout_constraintHorizontal_chainStyle=" packed"
app:layout_constraintStart_toStartOf="father"
app:layout_constraintTop_toTopOf="parent"。
android:text="Hello there I am a very very very very long text"。
tools:text="Hello there I am a very very very very long text" />。
<TextView
android:id="@ id/rightTv"
android:layout_width="0dp"/span>
android:layout_height="wrap_content"。
android:layout_marginStart="16dp"。
android:layout_marginLeft="16dp"。
android:textColor="#21b38a"/span>
android:textSize="16sp"。
android:ellipsize="end"。
android:maxLines="1"。
app:layout_constraintBottom_toBottomOf="father"
app:layout_constraintEnd_toEndOf="parent"。
app:layout_constraintStart_toEndOf="@ id/leftTv"
app:layout_constraintTop_toTopOf="father"
android:text="Hello there I am a very very very very long text"。
tools:text="Hello there I am a very very very very long text" />。
</androidx.constraintlayout.widget.ConstraintLayout>
我的代碼輸出是這樣的:
| [Hello there I am a very...] [Hello there I am a very...] |。
這里有一些我在發帖前檢查過的帖子。
轉載請註明出處,本文鏈接:https://www.uj5u.com/qiye/329139.html
標籤:

