tags:

views:

2131

answers:

3

I want to lay two TextView to the left, and one button to the right inside a linear layout, is this possible? The following is my code where I had to hardcode the leftMargin of the button, this is inflexible. Is it possible to layout children that flows in different directions?

<LinearLayout
android:id="@+id/widget43"
android:layout_width="fill_parent"
android:layout_height="100px"
>
<TextView
android:id="@+id/tc_buttom_text1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Time elapsed"
>
</TextView>
<TextView
android:id="@+id/tc_buttom_text2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="00:00:00 00"
>
</TextView>
<Button
android:id="@+id/tc2_home"
android:layout_width="70px"
android:layout_height="wrap_content"
android:layout_marginLeft="200px"
android:layout_marginRight="10px"
android:text="Home"
android:layout_weight="0.5"
>
</Button>
</LinearLayout>
+1  A: 

I want to lay two TextView to the left, and one button to the right inside a linear layout, is this possible?

Not with a single LinearLayout. You either need two LinearLayouts (one for a column of two TextViews on the left), or one RelativeLayout.

Is it possible to layout children that flows in different directions?

If by "different directions" you mean both vertical and horizontal simultaneously, a single LinearLayout can only go in one direction. Either use nested LinearLayouts or a RelativeLayout.

CommonsWare
A: 

LinearLayout has an orientation attribute. Try something like this:

<LinearLayout
    android:id="@+id/widget43"
    android:orientation="horizontal"
    android:layout_width="fill_parent"
    android:layout_height="100px"
>
Mike Mazur
A: 

You need to use Table layout. look at table layout example in API demos.

Table layout - with 'stretch columns' = 1, -- Table row - with width = fill_parent, -- Text View, -- Text View, -- Button,

This will keep your right button pushed to the right edge of the screen

Rahul