Android布局中gravity与layout如何用
在Android布局中,gravity和layout是两个区分的属性,可以用来控制视图在布局中的位置和对齐方式。
<TextView
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:text="Hello World!"
    android:gravity="center_horizontal|center_vertical"/>
<RelativeLayout
    android:layout_width="match_parent"
    android:layout_height="match_parent">
    <Button
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:text="Button"
        android:layout_alignParentTop="true"
        android:layout_alignParentLeft="true"/>
</RelativeLayout>
总结:Gravity用来控制视图内容在其可用空间内的对齐方式,而Layout用来控制视图在父布局中的位置和大小。根据具体需求选择适合的属性来布局。
                TOP