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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T10:34:07+00:00 2026-05-27T10:34:07+00:00

Is it possible to dynamically re-size fonts in a textview according to screen resolution?

  • 0

Is it possible to dynamically re-size fonts in a textview according to screen resolution? If yes how? I’m developing from an mdpi avd. But when the app is installed on hdpi text appears too small.

  • 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-27T10:34:08+00:00Added an answer on May 27, 2026 at 10:34 am

    Use textSize and the scaled pixels sp unit is what alextsc is implying.

    If you realy want to be dynmic and make you font as big as possible to fill up the width then it is possible with a textWatcher to render the text and check the size and then tweak the fonts on the fly.

    The following is rather specific as I have multiple text views in a linear layout and this only resizes the text smaller once the text in one of them will not fit. It will give you something to work with though.

    class LineTextWatcher implements TextWatcher {
    
    static final String TAG = "IpBike";
    TextView mTV;
    Paint mPaint;
    
    public LineTextWatcher(TextView text) {
        mTV = text;
        mPaint = new Paint();
    }
    
    public void beforeTextChanged(CharSequence s, int start, int count,
            int after) {
    }
    
    public void onTextChanged(CharSequence s, int start, int before, int count) {
    }
    
    public void afterTextChanged(Editable s) {
        // do the work here.
        // we are looking for the text not fitting.
        ViewParent vp = mTV.getParent();
        if ((vp != null) && (vp instanceof LinearLayout)) {
            LinearLayout parent = (LinearLayout) vp;
            if (parent.getVisibility() == View.VISIBLE) {
                mPaint.setTextSize(mTV.getTextSize());
                final float size = mPaint.measureText(s.toString());
                if ((int) size > mTV.getWidth()) {
                    float ts = mTV.getTextSize();
                    Log.w(TAG, "Text ellipsized TextSize was: " + ts);
                    for (int i = 0; i < parent.getChildCount(); i++) {
                        View child = parent.getChildAt(i);
                        if ((child != null) && (child instanceof TextView)) {
                            TextView tv = (TextView) child;
                            // first off we want to keep the verticle
                            // height.
                            tv.setHeight(tv.getHeight()); // freeze the
                                                          // height.
    
                            tv.setTextSize(TypedValue.COMPLEX_UNIT_PX,
                                    tv.getTextSize() - 1);
                        } else {
                            Log.v(TAG, "afterTextChanged Child not textView");
                        }
                    }
                }
            }
        } else {
            Log.v(TAG, "afterTextChanged parent not LinearLayout");
        }
    }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I know its possible to increase the size of a dynamically allocated array. But
Is it possible to subclass dynamically? I know there's ____bases____ but I don't want
Is it possible to dynamically control the font size in a text area /
Possible Duplicate: Is it possible to dynamically create an array of constant size in
Possible Duplicate: Dynamically adding collapsible elements I've seen a few posts on this but
Depending by the size of the app interface, I need to adapt dynamically the
Is it possible to dynamically create and modify images on a per pixel level
Does someone knows if it's possible to dynamically create a call chain and invoke
I am curious if it is possible to dynamically build a list comprehension in
I was wondering if it were possible to dynamically create an XML layout file

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.