How do I wrap a second text around first text title, both are in text view

北慕城南 提交于 2020-01-17 06:17:31

问题


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:


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.



来源:https://stackoverflow.com/questions/23087668/how-do-i-wrap-a-second-text-around-first-text-title-both-are-in-text-view

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!