I have been trying to use layout_gravity
in a horizontal linear layout
. But it doesn't seem to work. I don't want to use a relative layout
or any other layout. I want to know why it is not working with linear layout
.I have earlier used layout_gravity
in vertical
linear layouts and it has worked in the way I expected.
<LinearLayout
android:id="@+id/shata"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
>
<TextView
android:id="@+id/title_textview"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:textColor="@color/black"
android:text="shata1"
android:textAppearance="?android:attr/textAppearanceMedium"
/>
<TextView
android:id="@+id/map_imageview"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_gravity="right"
android:textAppearance="?android:attr/textAppearanceMedium"
android:text="shata2"/>
</LinearLayout>
As you can see the the linear layout has a orientation=horizontal
and width=match_parent
(it is just inside the root layout). But both the TextViews are displayed sticking to the left of the LinearLayout
even though I have given their layout_gravity=center
and layout_gravity=right
respectively.
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…