Tuesday, October 29, 2013

[android-developers] Re: getDensity returning 0 in attempt to create pixel density independant controls

I found the answer to this on stack overflow here: getting the screen density programmatically in android?

Use getResources().getDisplayMetrics().density or context.getResources().getDisplayMetrics().density to get:

0.75 - ldpi

1.0 - mdpi

1.5 - hdpi

2.0 - xhdpi

3.0 - xxhdpi

4.0 - xxxhdp

 

On Tuesday, October 29, 2013 7:54:28 AM UTC-5, firebreather wrote:
i'm attempting to draw pixel density and resolution independent controls to the screen for my game.
 
 if I use screenWidth in declaring the size, the control's size will vary with resolution. if I just use a certain number of pixels, the control size will vary with pixel density.
 
assume i need canvas.getDensity(), as there is no action like
 

canvas.drawCircle(cx,cy,60di,paint). //di: density independent pixel

canvas.getDensity() is returning 0, however. I saw on a different post a suggestion of disabling the GPU to fix this. I don't want to disable the GPU on my user's phones' though, even if I knew how. how do I get around this?

--
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to android-developers@googlegroups.com
To unsubscribe from this group, send email to
android-developers+unsubscribe@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en
---
You received this message because you are subscribed to the Google Groups "Android Developers" group.
To unsubscribe from this group and stop receiving emails from it, send an email to android-developers+unsubscribe@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.

0 Comments:

Post a Comment

Subscribe to Post Comments [Atom]

<< Home


Real Estate