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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T09:27:03+00:00 2026-06-04T09:27:03+00:00

On mdpi device I would like to call this method: final float scale =

  • 0

On mdpi device I would like to call this method:

final float scale = getResources().getDisplayMetrics().density;
double height_px =  45 * scale + 0.5;

but I want to ignore the method when the app is run on hdpi devices, how am I able to determine the screen size on my class?

  • 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-04T09:27:04+00:00Added an answer on June 4, 2026 at 9:27 am

    Yeah simply you can check for scale value like this,

    final float scale = getResources().getDisplayMetrics().density;
    

    And now you have scale value. The scale value varies like this,

    For MDPI devices, scale value is 1.0.

    For LDPI devices, scale value is 0.75.

    For HDPI devices, scale value is 1.50.

    For XHDPI devices, scale value is 2.0.

    Just make a cross check,

    if(scale <1.50)
    {
    double height_px =  45 * scale + 0.5;
    }
    

    Which means this code will not be executed for High and above resolutions.

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

Sidebar

Related Questions

I need a way to say if device is LDPI or MDPI or HDPI
I find that JQuery Mobile pages look good on MDPI devices (like G1) but
I have drawables for each density as ldpi,mdpi,hdpi and xhdpi. Problem: Both 10 tablet
I'm working on a J2ME applicatoin using LWUIT and would like to support most
Do you create the MDPI drawable first and just scale it accordinly to the
My device configuration is large-mdpi. But in my app, i have the images only
When you call: Bitmap b = BitmapFactory.decodeResource(getResources(), R.drawable.disco); Which version of disco will be
whats this file ?!!! i don't delete it !! java.io.FileNotFoundException: res/drawable-mdpi/scrollbar_handle_vertical.9.png 12-06 14:26:33.606: ERROR/AndroidRuntime(276):
I would like to know if it's possible to specify more than just drawable-ldpi,
So on device there's the drawable directories for hdpi, mdpi, ldpi etc... Now lets

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.