如何让文本居右对齐,换行后又居左对齐 效果图 实现方案

效果图

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