0

My problem is the following. I have 4 TextView that I aligned horizontally. Among these 4 textviews, the first 2 can take only 1 line, while the other 2 can take 1 or 2 lines. However I would like that, when I go to the 2nd line, this would continue under the 1st textView, on the left (as if it was all a unique textview) and not below the place where the textview started. Think about facebook post for instance in which the first textview is the username and the second is the action he performed and, if the action is too long, then the text would continue under the username. Right now my code is the following:

<LinearLayout
            android:orientation="horizontal"
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:layout_alignParentLeft="true">

            <TextView
                android:id="@+id/status_display_name"
                android:layout_height="wrap_content"
                android:layout_width="wrap_content"
                android:textColor="?android:textColorPrimary"
                android:textStyle="normal|bold"
                android:ellipsize="end"
                android:maxLines="1"
                android:text="Name "
                 />

            <TextView
                android:id="@+id/status_display_family_name"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:textColor="?android:textColorPrimary"
                android:maxLines="1"
                android:ellipsize="end"
                android:text="Family name"
                android:paddingRight="@dimen/status_display_name_right_padding"/>
            <TextView
                android:id="@+id/status_display_action"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:textColor="?android:textColorSecondary"
                android:maxLines="2"
                android:ellipsize="end"
                android:text="has done " />
            <TextView
                android:id="@+id/status_display_item_title"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:textColor="?android:textColorPrimary"
                android:maxLines="2"
                android:ellipsize="end"
                android:text="My item title" />
        </LinearLayout>
Seba92
  • 446
  • 1
  • 4
  • 17

1 Answers1

0

The best solution for your problem that I can suggest you is to use One (1) instead of Four (4) text views. Append all the texts of your four text views and set it to the single text view like this:

 yourTextView.setText(displayName + " " + familyName + " " + displayAction + " " + displayItemTitle);

And your layout will be like this:

<LinearLayout
        android:orientation="vertical"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:layout_alignParentLeft="true">

        <TextView
            android:id="@+id/your_single_textview"
            android:layout_height="wrap_content"
            android:layout_width="wrap_content"
            android:textColor="?android:textColorPrimary"
            android:textStyle="normal|bold"
            android:text="Name "
             />

    </LinearLayout>

And if you want to set your some text bold but some text normal then you can achieve that. Check this link:

how to make a specific text on TextView BOLD

Zohaib Hassan
  • 984
  • 2
  • 7
  • 11
  • but then I guess there would be no way to distinguish when the user clicks on the item or on the name, so it would not be exactly what I was looking for.. – Seba92 Jun 25 '17 at 08:37
  • well, actually maybe it should be possible https://stackoverflow.com/questions/10696986/how-to-set-the-part-of-the-text-view-is-clickable – Seba92 Jun 25 '17 at 08:55
  • It seems so, try it. I'll look for more options and will get back to you soon. – Zohaib Hassan Jun 25 '17 at 10:37