Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8205577
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T08:17:57+00:00 2026-06-07T08:17:57+00:00

I have two textviews like this: ======================= = TextView1 TextView2 = ======================= And I

  • 0

I have two textviews like this:

=======================
= TextView1 TextView2 =
=======================

And I would like to detect when the textviews are too long such that they are displayed like this:

=======================
=      TextView1      =
=      TextView2      =
=======================

currently for longer text, it is displayed like this:

=======================
= TextView1 Text      =
=           View2     =
=======================

how can I do this, such that when the text is short the textviews are side by side and when it is too long, the second textview is not splitted but moved to the second line?

I tought at a solution to create a single textview and build the text according to length (text 1 + padding + text 2 if short, and text 1 + “\n” + text 2 if long) but I do not like this solution.

Is there any way to detect if the second text will be split such that to change the orientation of the layout that contains the textviews from horizontal cu vertical?

UPDATE

This is my xml:

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
              android:layout_width="fill_parent"
              android:layout_height="fill_parent"
              android:gravity="center">

    <TextView
        android:id="@+id/my_text_1"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_gravity="center_vertical"
        android:padding="10dp"
        android:text="@string/text1"/>

    <TextView
        android:id="@+id/my_text_2"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_gravity="center_vertical"
        android:layout_marginRight="5dp"/>

</LinearLayout>
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-07T08:17:59+00:00Added an answer on June 7, 2026 at 8:17 am

    I have found a better solution. Changed my textviews into autoresizable textviews (more info here)

    Also, each textview is in a separate layout, to make sure both textviews are resized to the same value.
    My xml looks like this:

    <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
                  android:layout_width="fill_parent"
                  android:layout_height="fill_parent"
                  android:id="@+id/value_linear_layout"
                  android:gravity="center">
    
        <LinearLayout 
                android:layout_width="wrap_content"
                android:layout_weight="1"
                android:layout_height="wrap_content">
            <com.mihaela.view.AutoResizeTextView
                android:id="@+id/my_text_1"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"/>
        </LinearLayout>
    
        <LinearLayout 
                android:layout_width="wrap_content"
                android:layout_weight="1"
                android:layout_height="wrap_content">
    
            <com.mihaela.view.AutoResizeTextView
                android:id="@+id/my_text_2"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"/>
        </LinearLayout>
    
    </LinearLayout>
    

    and I have implemented the OnTextResizeListener from AutoResizeTextView to do this:

    public class TextWidthResizeListener implements OnTextResizeListener {
    
        @Override
        public void onTextResize(TextView textView, float oldSize, float newSize) {
            TextPaint paint = textView.getPaint();
            if (paint.measureText(textView.getText().toString()) > (valueLinearLayout.getWidth() / 2)){
                valueLinearLayout.setOrientation(LinearLayout.VERTICAL);
            }
        }
    }
    

    where valueLinearLayout is:

    valueLinearLayout = (LinearLayout)findViewById(R.id.value_linear_layout);
    

    This solution best fits for me, as the textviews are dimensioned when they are side by side until a minimum size. When the minimum size is reached, and the text still does not fit, the textviews will be aligned one under another.

    Also, this idea with the listener can be applied to non-resizable textviews also.
    I will set this answer as the correct one.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a listlayout with items in it that looks like this: There is
I have two TextViews that displays numbers from 1-6, I need to make a
I would like to have two linear layouts inside a third parent layout. I
I have two textviews, a listview (this is a listactivity, by the way) and
I have a problem with two Textviews on the same height in a RelativeLayout
I have two columns say Main and Sub . (they can be of same
I have added two textview in iphone by this way. I have two UITextView
I have a FrameLayout in which I have placed two identical TextViews. I want
I have a TabHost that has two ViewFlippers, and inside each ViewFlipper are three
I have created a compound control that I am reusing in multiple activities. This

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.