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 3870726
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 19, 20262026-05-19T21:45:20+00:00 2026-05-19T21:45:20+00:00

I have some text that will be put in a TextView . I did

  • 0

I have some text that will be put in a TextView. I did that using setText().

Now I need to find the number of lines or height the text occupies in the TextView. I tried using getHeight(), but it always returns 0.

Is there anyway to get the height of the text present in the TextView?

  • 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-19T21:45:20+00:00Added an answer on May 19, 2026 at 9:45 pm

    As John pointed out, you won’t be able to get the height immediately after setText. I’m not sure using getHeight() on the TextView itself will help you much. The height of the view is not only dependant on the height of the visible text in the view, but also on the viewgroup/layout the TextView resides in. If the viewgroup tells the TextView to maximize height, getHeight() will get you nowhere even if you wait until after the text is rendered.

    I see a number of ways that this could be done:

    1. Subclass TextView and overwrite the onSizeChanged method. In there, call supers onSizeChanged, then get the number of lines within the TextView by getLineCount() and the height per line with getLineHeight(). This might or might not be better than using getHeight(), depending on your layout or whatnot.
    2. Don’t use the Textviews dimensions. Get the TextViews Paint with TextView.getPaint(), and then calculate the width and height from

      Rect bounds;
      paint.getTextBounds(text, 0, text.length(), bounds);

    You’ll now have the dimensions in bounds. You can now work with paint.breakText to see how much text you’ll fit on one line. Probably too much hassle and not guaranteed (to my untrained eye) to be the same logic as used by TextView.

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

Sidebar

Related Questions

I have some unicode text that I want to clean up using regular expressions.
I have a little c# console program that outputs some text using Console.WriteLine. I
I've been trying to deal with some delimited text files that have non standard
I have a simple WPF (XAML) file that has some animated shapes and text.
I have some code in .Net to draw some text content using GDI+. I
I have some Tkinter canvas and some picture of lines and text on it.
I have some dynamic text contained in a div that is set to whatever
I often have data in Excel or text that I need to get into
I have an HTML form consisting of some text-inputs. I'm using jqTransform to prettify
I have a WPF combobox <ComboBox Name=cmbExpression IsEditable=True/> Now I have written some text

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.