In my horizontal LinearLayout, I set the gravity in one view to be center_vertical, and then I tried to set layout_gravity for a second view, but that view is lined up with the centered text in the first view!
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="horizontal" >
<TextView
android:layout_width="100dp"
android:layout_height="200dp"
android:layout_gravity="top"
android:background="@drawable/border"
android:gravity="center_vertical"
android:text="layout_gravity=top gravity=center_vertical" >
</TextView>
<TextView
android:layout_width="100dp"
android:layout_height="200dp"
android:layout_gravity="top"
android:background="@drawable/border"
android:gravity="top"
android:text="layout_gravity=top gravity=top" >
</TextView>
</LinearLayout>
And here is the same code but for a vertical layout. Notice that the desired behavior works correctly in the vertical layout.
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >
<TextView
android:layout_width="200dp"
android:layout_height="100dp"
android:layout_gravity="left"
android:background="@drawable/border"
android:gravity="center_horizontal"
android:text="layout_gravity=left gravity=center_horizontal" >
</TextView>
<TextView
android:layout_width="200dp"
android:layout_height="100dp"
android:layout_gravity="right"
android:background="@drawable/border"
android:gravity="right"
android:text="layout_gravity=right gravity=right" >
</TextView>
</LinearLayout>
I can just use a RelativeLayout or maybe another nested LinearLayout to fix the problem. But I am asking this question because I would like to know if I am not understanding how gravity and layout_gravity works!! It is important to me that I understand how these fundamental attributes work. Thanks