views:

56

answers:

2

Let's say you want to have a TextView and a Button in a Layout with horizontal orientation. Can you have the TextView aligned to the left and the Button - to the right?

---------------------
TextView       Button
---------------------
+2  A: 

Use a relative layout and position the second view to right.

android:layout_toRightOf="@id/firstView"
android:layout_alignTop="@id/firstView"
ktingle
+1  A: 

1) Use a RelativeLayout and android:layout_alignParentLeft="true" on one and android:layout_alignParentRight="true" on the other.

2) Use a LinearLayout with android:orientation="horizontal", and set android:gravity="left" & android:layout_weight="1" on one and android:gravity="right" & android:layout_weight="1" on the other (yes, the weight is required!)

Note, using layout_toRightOf will give left/right relative positioning but it won't force them to the edge of the screen/parent container.

TWH