1

I'm trying to organize two TextViews to behave like that:

Example

So, if there is enough space for both TextViews in line, android should place them in line.

If there is not enough space, the second TextView must be placed on the next line with right alignment.

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:orientation="horizontal" >

        <TextView
            android:id="@+id/takeoffCity"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            style="@style/flightItem" />

        <TextView
            android:id="@+id/landingCity"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            style="@style/flightItem" />
    </LinearLayout>

<style name="flightItem" parent="@android:style/TextAppearance">
    <item name="android:textSize">14dip</item>
    <item name="android:textColor">@color/flightItemFont</item>
    <item name="android:scrollHorizontally">true</item>
    <item name="android:textStyle">bold</item>
</style>
Jim Simson
  • 2,774
  • 3
  • 22
  • 30
bluebyte
  • 560
  • 2
  • 7
  • 23

1 Answers1

0

To accomplish what you are looking for you could change you're layout to a RelativeLayout and add android:layout_alignParentLeft="true" to your TextViews, however, this doesn't set these TextViews to act dynamically. Meaning if they can fit side-by-side then they should be in-line but the bottom TextView will still align to the right.

I don't think what you are looking for is technically possible. However this may be a good alternative:

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:orientation="horizontal" >

    <TextView
        android:id="@+id/takeoffCity"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentLeft="true"
        style="@style/flightItem" />

    <TextView
        android:id="@+id/landingCity"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentRight="true"
        style="@style/flightItem" />

</RelativeLayout>
jnthnjns
  • 8,962
  • 4
  • 42
  • 65