Why dp used in the XML files are not the same as dp used in activities? When I create a textView in the XML file with 20dp of width, its size will be the same in all different type of screens, but when I use this:
int sizeInDip = 20;
int width= TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, sizeInDip, getResources().getDisplayMetrics());
The size is different in all types of screen.
I want to know if there's a way to get the same result using dp in both, activities and XML files.
Thank you in advance!