-2

I want my app to showing views the same way on any device. I want to determine size in PIXELS. Can I do it? Can I just turn off that dpi resize feature, or set custom dpi for my app?

user1748526
  • 464
  • 5
  • 18

3 Answers3

1

You can use "px", "in", "mm", etc to specify absolute sizes.

G. Blake Meike
  • 6,615
  • 3
  • 24
  • 40
  • Thanks, this is it. But how I can use px in java, not xml? And this is kind of dirty way. Maybe exists some global dpi setting for the app? – user1748526 Feb 28 '13 at 19:46
  • The DPI for a device is compiled in to each device's version of Android. How to get that is described here: http://stackoverflow.com/questions/3166501/getting-the-screen-density-programmatically-in-android . – G. Blake Meike Feb 28 '13 at 19:56
0

Use "dp" (Density-independent Pixels) for all your coordinates and measurements. For example if you're specifying the margin for a layout, it would be...

android:layout_margin="5dp"

Using dp will automatically fit your layouts to any screen size.

http://developer.android.com/guide/practices/screens_support.html

labatyo
  • 486
  • 8
  • 17
0

DPI is the pixel density of the devices. You cannot change the pixel density of the device. Similarly, defining everything in pixels won't work because different devices have different amounts of pixels on screens of different sizes.

I realize that this wasn't really your intent, but that's essentially what you are asking.

Android provides quite a number of features that you can utilize to ensure your application looks good on all screens. You can learn about them on the Supporting Multiple Screens page of the Android Developer guide.

If you have a question about how to get a specific layout or feature to work with different devices, I encourage you to post another question with screenshots and the code that it is not living up to your expectations.

Bryan Herbst
  • 66,602
  • 10
  • 133
  • 120