0

I am trying to wrap a second text around the first text, both in relative layout and textview such that :

<RelativeLayout
        android:id="@+id/headlineRelativeLayout"
        android:layout_width="match_parent"
        android:layout_height="wrap_content">

        <TextView
            android:id="@+id/text1"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:paddingLeft="2dp"
            android:paddingRight="2dp"
            foo:customFont="proxima-nova-bold.ttf"
            android:textColor="@color/orange"
            android:textSize="@dimen/title" 
            android:gravity="left"
        />

        <TextView
            android:id="@+id/text2"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:ellipsize="end"
            android:maxLines="2"
            android:paddingLeft="2dp"
            android:paddingRight="2dp"
            android:layout_toRightOf="@id/text1"
            foo:customFont="proxima-nova-regular.ttf"
            android:textColor="@color/green"
            android:textSize="@dimen/title"
            android:gravity="left"
             />

    </RelativeLayout>

So, what I am currently getting is :

TEXT1 (TEXT 2 STUFF IS A SENTENCE WHICH
       SHOULD WRAP AROUND)

bUT WHAT i expect is :

TEXT1 (TEXT 2 STUFF IS A SENTENCE WHICH
WHICH SHOULD WRAP AROUND)

Any clue?

1 Answers1

0

I may have missed something here, but what you re getting is what I would expect. Each TextView is a rectangular box into which the text is rendered. If you want, you can overlay the boxes, but then the 'TEXT 1' and 'TEXT 2' would lie on top of each other.

To achieve what you want, you will have to think more carefully about what you are doing, and perhaps have three TextViewss:

<TextView 1><TextView 2>
<..... TextView 3 .....>

Whenever you set the text in TextView 2, set it to only show one line and find out how far it got. Then send the rest of the string to TextView 3.

Neil Townsend
  • 6,024
  • 5
  • 35
  • 52
  • You could also use a single TextView and [`Spannable`](http://stackoverflow.com/questions/6612316/how-set-spannable-object-font-with-custom-font) texts with different fonts. Then you wouldn't have to worry about splitting/alignment. – Geobits Apr 15 '14 at 19:25
  • @Geobits Can you provide an example for my case with textview.The example you are pointing to seems to be some typeface font thing. –  Apr 16 '14 at 00:12
  • @bardu The answer there shows how to use two typefaces in one TextView. Since the only difference I see in your two are typeface and color, I thought that would help. – Geobits Apr 16 '14 at 00:14
  • @Geobits I think you are right that it could be solved by using a spannable string with two sections. I think that Bardu is asking for sample code for that ... – Neil Townsend Apr 16 '14 at 20:00