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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T22:43:11+00:00 2026-06-17T22:43:11+00:00

Because of specific needs, in my android layout, I have used mm to provide

  • 0

Because of specific needs, in my android layout, I have used “mm” to provide size. In TextView also, I have provided sizes in “mm”. When I do textView.getTextSize(), the size returned is always in pixel values. I want to convert that pixel value in “mm”. For example, if I have set font size as “2mm”, then on any device, when I do getTextSize(), I would like to get “2mm”.

Should I use any specific method for that? I could find answers to convert “mm” to “pixel” but could not find anything about converting vice-versa.

  • 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-17T22:43:12+00:00Added an answer on June 17, 2026 at 10:43 pm

    we use TypedValue.java

    float px = TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_MM, 1, 
                    getResources().getDisplayMetrics());
    
      public static float applyDimension(int unit, float value,
                                           DisplayMetrics metrics)
        {
            switch (unit) {
            case COMPLEX_UNIT_PX:
                return value;
            case COMPLEX_UNIT_DIP:
                return value * metrics.density;
            case COMPLEX_UNIT_SP:
                return value * metrics.scaledDensity;
            case COMPLEX_UNIT_PT:
                return value * metrics.xdpi * (1.0f/72);
            case COMPLEX_UNIT_IN:
                return value * metrics.xdpi;
            case COMPLEX_UNIT_MM:
                return value * metrics.xdpi * (1.0f/25.4f);
            }
            return 0;
        }
    

    So you can try

    Pix = mm * metrics.xdpi * (1.0f/25.4f);

    MM = pix / metrics.xdpi * 25.4f;

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

Sidebar

Related Questions

I am developing an Android app which needs to poll a specific webpage in
I have a specific script written in Ruby that needs root privileges. Most of
I've searched everywhere and used some examples but they don't meet my specific needs,
Googling has been difficult because I can't get results specific enough - wondering if
First of all I can't post any specific info about project because it has
I have a specific function on an app that is intended to work on
I have a partial view that sometimes needs to collect data and sometimes just
I have an ant build script that builds many android projects. I am building
My Android app is displaying text in a TextView. Are there any tags or
I need to have some functionality in my web app where a specific action

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.