多textView设置布局居中显示文本左对齐或右对齐

在textView上层套一个ViewGroup即可,如

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent">
    
    <LinearLayout
        android:layout_centerInParent="true"
        android:layout_width="wrap_content"
        android:orientation="vertical"
        android:layout_height="wrap_content">
        <TextView
            android:text="今晚有点累?"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"/>
        <TextView
            android:text="补了不了?"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"/>
    </LinearLayout>
</RelativeLayout>

效果如下图:

 

posted @ 2020-10-23 20:18  小老弟呀  阅读(1384)  评论(0编辑  收藏  举报