dimanche 17 mai 2015

Android align multiple TextView-s in line

i am trying to align multiple (variable) textviews in one line. It should look like this:

- Textview1 | Textview2 | TextView3

Since the textviews vary regarding length I am having a problem aligning them properly(the only thing I know is that Textview1 will be the shortest one).

Here is my code (it is placed inside a Linear Layout):

        <RelativeLayout
            android:id="@+id/persondetails_names_horizontal_container"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_gravity="right"
            android:gravity="right" >

            <TextView
                android:id="@+id/persondetails_title"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_gravity="right"
                android:paddingTop="3dp"
                android:text=" Title "
                android:layout_alignParentRight="true" />

            <TextView
                android:id="@+id/persondetails_name"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:text=" Name "
                android:textSize="@dimen/font_big"
                android:textStyle="bold" 
                android:layout_toEndOf="@id/persondetails_title"
                android:layout_toRightOf="@id/persondetails_title" />

            <TextView
                android:id="@+id/persondetails_surname"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_toEndOf="@id/persondetails_name"
                android:layout_toRightOf="@id/persondetails_name"
                android:text=" Surname " />

        </RelativeLayout>

Now, as long as these 3 Textviews fill out one line on the screen everything is OK, but as soon as one of them gets bigger I get some problems. For example, when I put the surname field very long, it pushes the other 2 views out of the screen (they are not visible) and takes all the space (but just one line!).

What i want is that these views are aligned to the right side, each of them to the right of the previous one, and when it is needed to linebreak into a new line (no mather which textview it is) and in the new line the following textviews should align to the right of it.

Thank you

Aucun commentaire:

Enregistrer un commentaire