簡體   English   中英

width="wrap_content" 的文本視圖將另一個文本視圖推出屏幕

[英]Textviews with width="wrap_content" is pushing another textview out of the screen

我想在 Android Cardview 中實現這種行為,如圖 1 和 2 所示

當第一個文本視圖中的文本大於文本視圖的寬度時,第一個文本視圖的寬度 wrap_content 和下一個文本視圖 [也具有 width="wrap content"] 與第一個文本視圖的末尾對齊。 然后它在行的中間顯示 3 個點 [ellipsize="middle"] 但是當文本很小時它表現正常並且第二個文本視圖與其對齊而不完全對齊屏幕的右側。 那么我該如何實現呢。 請分享您將如何實現它的代碼

第一張圖片

第二張照片

我嘗試了 RelativeLayout 但是當第一個 textview 變得更寬時它將第二個 textview 推出屏幕

嘗試使用具有布局權重的線性布局。

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
        xmlns:tools="http://schemas.android.com/tools"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:orientation="horizontal"
        android:weightSum="1">
    
        <TextView
            android:layout_width="0dp"
            android:layout_height="wrap_content"
            android:layout_weight="0.8"
            android:gravity="center"
            android:text="sdssdsds"
            android:ellipsize="end"
            android:maxLines="1"
            android:textSize="16sp" />
    
        <ImageView
            android:layout_width="0dp"
            android:layout_height="wrap_content"
            android:layout_weight="0.2"
            android:src="@drawable/cross" />
    
    
    </LinearLayout>

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM