美文网首页
如何让文本居右对齐,换行后又居左对齐

如何让文本居右对齐,换行后又居左对齐

作者: 蓝不蓝编程 | 来源:发表于2020-10-24 17:34 被阅读0次

效果图

  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>

相关文章

网友评论

      本文标题:如何让文本居右对齐,换行后又居左对齐

      本文链接:https://www.haomeiwen.com/subject/vtcwmktx.html