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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T06:49:24+00:00 2026-05-25T06:49:24+00:00

I have asked this before however I am still having issues with this problem!

  • 0

I have asked this before however I am still having issues with this problem!

Basically, I am hardcoding pixel values when using a canvas to draw images for a game.

How would I go about the process of making this game suitable for any screen size as obviously the pixel values for one screen wont run properly on a different screen!

Thanks in advance

Ben

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

    Why do you need pixel values? Use dp not px values!!

    final float scale = getContext().getResources().getDisplayMetrics().density;
    int px = (int) (dp * scale + 0.5f);
    

    dp Density-independent Pixels – an abstract unit that is based on the
    physical density of the screen. These units are relative to a 160 dpi
    (dots per inch) screen, so 160dp is always one inch regardless of the
    screen density. The ratio of dp-to-pixel will change with the screen
    density, but not necessarily in direct proportion. You should use
    these units when specifying view dimensions in your layout, so the UI
    properly scales to render at the same actual size on different
    screens. (The compiler accepts both “dip” and “dp”, though “dp” is
    more consistent with “sp”.)

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

Sidebar

Related Questions

I have asked this question before and the problem was half solved in the
No doubt elements of this question have been asked before, but I'm having trouble
I asked this question before, Here however I think I presented the problem poorly,
I'm aware that this question may have been asked before, but I still haven't
I realise this question has been asked before however the previous answers have gotten
I have asked this before but I didn't get the question right so the
This question may have been asked before, but I had trouble finding an answer,
This seems to have been asked before: rails decimal precision and scale But when
This has / may have been asked before, but, as far as I remember,
I know this kind of questions have been asked already many times before. The

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.