How change location of the TextView depending on content

91 Views Asked by At

I have two TextView side by side in a LinearLayout horizontally

<LinearLayout
    android:layout_width="wrap_content"
    android:layout_height="wrap_content">

    <TextView
        android:id="@+id/Tx1"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="Message" />

    <TextView
        android:id="@+id/Tx2"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="Time" />

</LinearLayout>

i want when Tx1 text length is fill the line Tx2 go to next line

when now we add to length of the Tx1 , Tx2 is going outside of the view.

how i can fix it?

1

There are 1 best solutions below

0
BlackHatSamurai On

You most likely will have to do something programmatically with the orientation using a TextWatcher:

yourEditText.addTextChangedListener(new TextWatcher() {

            public void afterTextChanged(Editable s) {

            }

            public void beforeTextChanged(CharSequence s, int start, int count, int after) {}

            public void onTextChanged(CharSequence s, int start, int before, int count) {
            // You would have to define what your max length is. 
             if(count > maxLength){
                myLinearLayout.setOrientation(LinearLayout.VERTICAL);
             }

          }
        });