水平对齐:

1、LinearLayout添加属性:android:orientation="vertical";

2、元件添加属性:android:layout_gravity="center_horizontal"。

<LinearLayout
   android:layout_width="match_parent"
   android:layout_height="200dp"
   android:orientation="vertical">
  <TextView
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:gravity="center_horizontal"
        android:text="我要居中对齐呀~"/>
</LinearLayout>
 

垂直对齐:

1、LinearLayout添加属性:android:orientation="horizontal";

2、元件添加属性:android:layout_gravity="center_vertical"。

<LinearLayout
  android:layout_width="match_parent"
  android:layout_height="match_parent"
  android:orientation="horizontal" > 
  <TextView
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_gravity="center_vertical"
        android:text="我要垂直对齐呀~" />
</LinearLayout>

 

相关文章:

  • 2022-12-23
  • 2021-12-15
  • 2021-11-27
  • 2021-12-14
  • 2021-09-23
  • 2021-12-14
  • 2021-05-21
猜你喜欢
  • 2021-11-27
  • 2021-11-27
  • 2021-11-27
  • 2022-02-23
  • 2021-07-02
相关资源
相似解决方案