Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Dip to pixel conversion results in the exact same value

Tags:

java

android

I am trying to convert dips to pixels using the following function. I’ve tried low, medium, and high density emulators and regardless of the emulator I use, the pixel value remains the same value as the dip value I pass into the function.

private int ConvertDips(float dips) {
 int pixels = (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, (float) dips, getResources().getDisplayMetrics());
 return pixels;
}

What the heck am I doing wrong here?

like image 650
user432209 Avatar asked Nov 06 '22 07:11

user432209


1 Answers

This was my own fault. The emulator was basically lying to the system and telling my app it was resolution x-y. All part of what it was supposed to do according to the Android support screens documentation. I needed to properly set up resources within the correct folders so that it would no longer lie to my application.

like image 118
user432209 Avatar answered Nov 11 '22 03:11

user432209