HelloCW
HelloCW

Reputation: 2315

layout_gravity="right" don't make controls to right side in LinearLayout

In the following layout , I think the three controls textTotalTitle,textTotalValue and chAll will locate the right side of UI, but in fact, the three controls still stay the left side, why?

  <LinearLayout
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:layout_gravity="center_vertical"
        android:background="#DCDCDC"
        android:orientation="horizontal" >

        <TextView
            android:id="@+id/textSMSFilter"
            style="@style/myTextAppearance"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:gravity="center"
            android:paddingLeft="4dip"
            android:layout_gravity="left|center_vertical"
            android:text="@string/filter" >
        </TextView>

        <Spinner
            android:id="@+id/spinnerMsgFolder"
            android:layout_width="133dp"
            android:layout_height="wrap_content"
            android:layout_gravity="left|center_vertical"
            android:gravity="center" />

        <TextView
            android:id="@+id/textTotalTitle"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:gravity="center"
             android:layout_gravity="right|center_vertical"
            android:text="@string/totalAndSelectedTitle" >
        </TextView>

        <TextView
            android:id="@+id/textTotalValue"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:gravity="center"
            android:paddingLeft="3dip"
            android:paddingRight="2dip"
             android:layout_gravity="right|center_vertical"
            android:text="0/1" >
        </TextView>

        <CheckBox
            android:id="@+id/chAll"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
             android:layout_gravity="right|center_vertical"
            android:paddingRight="5dip" />
    </LinearLayout>

Upvotes: 0

Views: 2385

Answers (1)

JaredLuo
JaredLuo

Reputation: 491

That's because if android:orientation of LinearLayout is horizontal, the android:layout_gravity's value right and left will be not working.
You can only set it to top or bottom.

And if LinearLayout is vertical, you can set layout_gravity to left or right, but not top or bottom.
So, I think you should use RelativeLayout here...

Upvotes: 8

Related Questions