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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 29, 20262026-05-29T06:15:45+00:00 2026-05-29T06:15:45+00:00

Newbie Java question – On all the posts for Auto Scaling the Text view,

  • 0

Newbie Java question – On all the posts for Auto Scaling the Text view, no one indicates how you actually use the provided class. It looks like one of the better solutions is Chase’s at Auto Scale TextView Text to Fit within Bounds

Does anyone have an idea how you use it? For example:

String bigTextString = "This is a test!";

TextView t = (TextView)findViewById(R.id.big_text);
t.setTextSize(returnFontSize(bigTextString));
t.setText(bigTextString);

The returnFontSize does not exist and is just shown for illustration. The AutoResizeTextView class is set up properly in it’s own file.


Thanks (ignore the short comment below, as StackOverflow has a bug that doesn’t allow reediting a comment, and it’s also limited to 512 chars).

I must be still missing something. If I only use the two lines suggested where do you pass the text string? I tried something similar, but it just crashes when run, which makes sense.

AutoResizeTextView t = new AutoResizeTextView(this); 
linearMain.addView(findViewById(R.id.big_text));

The addView fails with a “IllegalStateException: The specified child already has a parent. You must call removeView() on the child’s parent first.”, which seems strange as I don’t want to remove the view (I think), and I don’t see how it has any idea of the string to put on screen.

Is a addView really necessary as it’s already defined in the layout.

I just want to pass it the text. For example:

TextView t = (TextView)findViewById(R.id.big_text);
t.setTextSize(textSize);
t.setTextColor(textColor);
t.setText(bigTextString);

This runs, except Android does a poor job of fitting the text on screen depending on what’s in “bigTextString”.

  • 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-29T06:15:46+00:00Added an answer on May 29, 2026 at 6:15 am

    Well if you have a class that describes how to make and modify an object, all you need to do is make it and modify it with its constructor and methods. Below is the one from your link.

    public FontFitTextView(Context context, AttributeSet attrs) {
        super(context, attrs);
    
        float size = this.getTextSize();
        if (size > MAX_TEXT_SIZE)
            setTextSize(MAX_TEXT_SIZE);
    }
    

    You call in your activity FontFitTextView textViewName = new FontFitTextView(context, attrs); and then add it to a view by layoutName.addView(textViewName); This means you need to find the view you are using for a layout by its android:id as I am assuming you dont want to build the whole layout programatically. You can also call the constructor in xml by <packagename.FontFitTextView />

    tl;dr – Use the constructor

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

Sidebar

Related Questions

Possible Duplicate: When do you use Java's @Override annotation and why? Newbie question -
Java Newbie question : I need to capture the text being written to a
Just a simple question from a relative Java newbie: what is the difference between
I am a newbie to Java Web Application development. So far all I have
Newbie here...can I write one program which incorporates .NET LINQ and also various Java
I'm learning Java, and I know one of the big complaints about newbie programmers
Sorry fot his newbie question. But I really need a start on this one.
Java/OO newbie question: main instantiates Track class. Now I want that object-- track1 --to
Ok so this is a newbie question on java, but i can't seem to
A newbie question. I have the following piece of Java code: import acm.program.*; import

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.