Mikooos
Mikooos

Reputation: 5430

Can I change device DPI programmatically?

I was wondering if I can change device which decides which layout it should choose or which graphic it should choose/scale. This change should only affect my application of course. Can I set somehow device DPI?

The reason why I'm doing that is this phone: http://www.gsmarena.com/samsung_p1000_galaxy_tab-3370.php it has very bad DPI od 240DPI while it's only 170PPI and should be recognized as 160DPI device. I have quite big graphic for layout-large which looks great on mdpi, but on hdpi they doesn't fit, they are just to big.

Maybe you have another solution than changing device DPI?

Upvotes: 6

Views: 11047

Answers (3)

Hassy31
Hassy31

Reputation: 2813

you should create your application to support with multiple screens.take a look at documentation

and hope these links helps you

Designing for Multiple Screens

Working with Multiple Android Screens

Upvotes: 4

filip1299
filip1299

Reputation: 221

Yes it is possible. The following will set the dpi to 240. Although you have to refresh the activity somehow e.g. restart application.

DisplayMetrics metrics = new DisplayMetrics();
getWindowManager().getDefaultDisplay().getMetrics(metrics);
metrics.density = 1.5f;
metrics.densityDpi = 240;
metrics.heightPixels = 1104;
metrics.widthPixels = 1920;
metrics.scaledDensity = 1.5f;
metrics.xdpi = 254.0f;
metrics.ydpi = 254.0f;
getResources().getDisplayMetrics().setTo(metrics);

Upvotes: 22

K_Anas
K_Anas

Reputation: 31456

Samsung Galaxy Tab GT-P1000 take layout from layout-xhdpi if this not there then it will look for large.

Try to support multiples screen resolution for your app based on that documentation you have to Design alternative layouts and drawables for your app

Upvotes: 0

Related Questions