Line break of a second android textview

2

I have two textview on the same line, the two textview do not have static content, the problem comes when the second textview is loaded with the data, it takes the second line but not from the left completely.
I hope you can help me.

The code is this:

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

            <TextView
                android:id="@+id/add"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:text="uno"
                android:visibility="visible"
                android:textSize="@dimen/msg_text_primary"
                android:textColor="@color/from"
                android:maxLines="1"
                android:layout_alignParentTop="true"
                android:layout_alignParentLeft="true"
                android:layout_alignParentStart="true" />
            <TextView
                android:id="@+id/text_titulo"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:text="titulo"
                android:ellipsize="end"
                android:textSize="@dimen/msg_text_primary"
                android:textColor="@color/from"
                android:maxLines="2"
                android:layout_alignParentTop="true"
                android:layout_toRightOf="@+id/add"
                android:layout_toEndOf="@+id/add"
                android:layout_marginLeft="2dp"
                android:layout_alignParentLeft="false"
                android:layout_toLeftOf="@+id/add"
               />

        </RelativeLayout>

The image:

This in the code that I have with the two textview

<LinearLayout
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:orientation="vertical">
            <TextView
                android:id="@+id/add"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:text="uno"
                android:visibility="visible"
                android:textSize="@dimen/msg_text_primary"
                android:textColor="@color/from"
                android:maxLines="1"
              />

                <TextView
                    android:id="@+id/text_titulo"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:text="titulo"
                    android:ellipsize="end"
                    android:textSize="@dimen/msg_text_primary"
                    android:textColor="@color/from"
                    android:maxLines="2"
                    android:singleLine="false"
                    android:nestedScrollingEnabled="false"
                    android:layout_gravity="left|center_vertical" />

        </LinearLayout>

EDIT

I want to do what is reflected in the image below, I have two values, the name and the description, what I do is set it in two textview, I try to achieve the behavior of the image below reflected ..

additional information reflected in bold is a textview, and the comment is another textview .. I appreciate the help.

    
asked by Josee Naava 01.08.2017 в 21:15
source

2 answers

1

Another option would be to use the spannable method, in which you only use a textView, example: You get 2 strings (one and two) and "format" the strings like this:

final SpannableString text = new SpannableString(uno);
final SpannableString text2 = new SpannableString(dos);
text.setSpan(new StyleSpan(Typeface.BOLD), 0, uno.length(), Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);        // texto en bold           
text.setSpan(new ForegroundColorSpan(Color.BLACK), 0, uno.length(), Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);   // texto color negro
text.setSpan(new RelativeSizeSpan(1.5f), 0, uno.length(), Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);   // tamaño 1.5f
text2.setSpan(new StyleSpan(Typeface.ITALIC), 0, dos.length(), Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);   // en italica
textView1.setText(TextUtils.concat(text," " ,text2));           // se concatena con text utils
    
answered by 16.05.2018 в 07:42
0

A simple option is to use a LinearLayout with vertical orientation:

<TextView
    android:id="@+id/add"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:text="uno"
    android:visibility="visible"
    android:textSize="@dimen/msg_text_primary"
    android:textColor="@color/from"
    android:maxLines="1" />
<TextView
    android:id="@+id/text_titulo"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:text="titulo"
    android:ellipsize="end"
    android:textSize="@dimen/msg_text_primary"
    android:textColor="@color/from"
    android:maxLines="2"
    android:layout_alignParentTop="true"
    android:layout_marginLeft="2dp"
    />

If you use a RelativeLayout, I advise you to check the operation of the following properties that you are using inappropriately.

            android:layout_alignParentLeft="true"
            android:layout_alignParentStart="true" 
            android:layout_alignParentLeft="false"
            android:layout_toLeftOf="@+id/add"
    
answered by 02.08.2017 в 04:51