layout_gravity是设置本控件(子控件)相对父类控件所在的位置
gravity:有两个作用
一:如果是在父类用:则子控件都是按照这个gravity的对齐方式放置
二:如果是用在子控件中,则是控件中文字的对象方式
例子:
<TextView
android:id="@+id/tv_activity_program_order"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="0.3"
android:gravity="center_horizontal"
android:layout_marginLeft="@id/tv_activity_program_program"
android:text=字体在中间"/>
则“字体在中间”字体是在子控件的中间
<LinearLayout
android:id="@+id/linear_activity_program_btn"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="right"
android:orientation="horizontal" >
<TextView
android:id="@+id/tv_activity_program_order"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="0.3"
android:layout_gravity="center_horizontal"
android:text="tv组件在中间"/>
则这个textview控件是放在父控件lineatLayout的中间
<LinearLayout
android:id="@+id/linear_activity_program_btn"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center"
android:orientation="horizontal" >
<TextView
android:id="@+id/tv_activity_program_order"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="0.3"
android:text="所有子控件都是在中间"/>
<TextView
android:id="@+id/tv_activity_program_order"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="0.3"
android:text="所有子控件都是在中间"/>
</LinearLayout>
则:这两个textview控件都会居中对齐