I need to convert dp
to pixeles
and pixeles
to dp
in Android Java.
I get the width of the screen of the device, I return a value float
that is in dp
public static float getWidthDeviceDP(Context context) {
DisplayMetrics displayMetrics = context.getResources().getDisplayMetrics();
return displayMetrics.widthPixels / displayMetrics.density;
}
and I want to define the minimum size of a TextView
with the method
tv.setMinWidth(<pixel>)