如何讓文本居右對齊,換行後又居左對齊 效果圖 實現方案

效果圖

  1. 一般做出來的效果



  2. 預期效果圖(差別在第二張)



預期效果: 文字單行居右對齊,多行居左對齊.

實現方案

  1. 讓目標文本控件內居左對齊
  2. 在目標控件外圍套一層相對佈局,佔滿橫向空間,讓文本控件在相對佈局中居右顯示 .
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:id="@+id/selectAddressLayout"
    android:layout_width="match_parent"
    android:layout_height="wrap_content">

    <TextView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="分類"
        android:textColor="#FF333333" />

    <RelativeLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content">

        <TextView
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_alignParentEnd="true"
            android:layout_marginStart="40dp"
            android:text="xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"
            android:textColor="#999999"
            tools:ignore="SpUsage" />

    </RelativeLayout>
</LinearLayout>
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章