Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Can I change device DPI programmatically?

Tags:

android

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?

like image 711
Mikooos Avatar asked May 25 '12 07:05

Mikooos


People also ask

How do you check DPI on Android?

To find the DPI, look at the Software Density entry under the Display section. For the Android version, look at the OS version under the Device section. This explicitly displays the version number.

Can you change DPI on phone?

Option 1 – Android 7 (Nougat) and HigherOpen “Settings” > “Display” > “Display size“. Use the slider to choose the setting you like.

How do I find my device DPI?

Finding Your DPI There are a handful of apps that can show you your DPI value, but the clear-cut best option is DPI Checker by TheViciousGames. It's super lightweight, open source, and does exactly what you need it to do and nothing more.


1 Answers

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);
like image 198
filip1299 Avatar answered Oct 05 '22 06:10

filip1299