layout_gravity not working

Eugene picture Eugene · Aug 29, 2012 · Viewed 20.5k times · Source

Why my TextView doesn't go right?

Update: Well, now I don't just need to set TextView to the right. Now it is very interesting why layout_gravity doesn't work as expected, namely - set the View to the position inside it parent container.

enter image description here

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
              android:layout_width="match_parent"
              android:layout_height="wrap_content"
              android:minHeight="?android:attr/listPreferredItemHeight"
              style="@style/activated_item"
              android:orientation="horizontal">

    <CheckBox
        android:id="@+id/star"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_gravity="center"
        android:layout_marginLeft="8dp"
        style="?android:attr/starStyle"/>

    <TextView
        android:id="@+id/title"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:textAppearance="?android:attr/textAppearanceMedium"
        android:layout_marginLeft="8dp"
        android:layout_gravity="right" //////// HERE I AM 
        android:textStyle="bold"
        android:textColor="@color/item_text_color"/>

</LinearLayout>

Answer

poitroae picture poitroae · Aug 29, 2012

Try to use gravity instead of layout_gravity.