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

  • SEARCH
  • Home
  • 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 7553573
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T11:05:51+00:00 2026-05-30T11:05:51+00:00

I’m trying to make a textview that scales the contents so that it all

  • 0

I’m trying to make a textview that scales the contents so that it all shows, no cropping, multi lines or elipsis.

I’ll quickly run through the layout just to put it into context.

*There’s a gridview with several rows and columns.
*The items for the gridview are provided by an adapter which returns (pseudo markup 🙂 ):-

<LinearLayout Orientation=vertical>
    <MyCustomTextview name='titletext' Not multiline />
    <MyCustomTextview name='itemtext' Not multiline />
</LinearLayout>

I’ve tried overriding onSizeChanged as this is where several google results pointed me and I started with:-

...
if (this.getLinecount() > 1)
{
    this.setTextSize(... currentsize -10);
}
...

and this gave me really small text where it would have appeared on more than one line, so I knew I could resize and find out if the TextView had more than one line correctly.

so I progressed to:-

while (this.getLinecount() > 1)
{
    this.setTextSize(... currentsize - 1);
}

which I expected to run until the text was small enough, but after the call to setTextSize getLineCount() returns 0, I believe this is because it needs to recalculate the text size so I tried various combinations of refreshLayout(), forceLayout() and invalidate() to no avail.

I’ve an idea for perhaps a better approach, but I don’t know if it’s easily attainable:-

onSizeChanged is called after it is put into the Gridview by the Adapter so I will execute my code there, but is the following possible and how:-

  • The TextView is set to a width of fill parent, can I accurately tell a pixel size of the width of available space for text? (I believe there may be padding and such applied)
  • I then intend to use measureText(String) to see if the text will fit, if not decrease size and check again.

I believe that would be a good solution, but I’m not sure on the accurate measurement of available space, and if the event I’ve chosen would be best.

Any assistance would be appreciated.

  • Anthony
  • 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-05-30T11:05:52+00:00Added an answer on May 30, 2026 at 11:05 am

    Why don’t you try the same sort of approach, but use measureText instead?

    while (mPaint.measureText(MyTextString)>mTextView.getWidth() ) //maybe adjust for padding/margins etc
    {
        mPaint.setTextSize(... currentsize - 1);
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
I'm trying to create an if statement in PHP that prevents a single post
I've got a string that has curly quotes in it. I'd like to replace
I am trying to render a haml file in a javascript response like so:
I am doing a simple coin flipping experiment for class that involves flipping a
I have a French site that I want to parse, but am running into
I would like to run a str_replace or preg_replace which looks for certain words
I'm trying to select an H1 element which is the second-child in its group
I have a text area in my form which accepts all possible characters from

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.