Skip to content Skip to sidebar Skip to footer

Confusion In "smallest Width Dp" In Android

I am learning how to use 'smallest width dp' to support different screens using this in android. i get that below number are the smallest of side of device in dp. Typical numbers

Solution 1:

You can get the correct values with the following code:

DisplayMetricsdisplayMetrics=this.getResources().getDisplayMetrics();
    floatdpHeight= displayMetrics.heightPixels / displayMetrics.density;
    floatdpWidth= displayMetrics.widthPixels / displayMetrics.density;
    Log.d("dpHeight-----",String.valueOf(dpHeight));
    Log.d("dpWidth------",String.valueOf(dpWidth));

For example for the Xperia Z 1080x1920px the values are 360x592dp, the settings is values-sw360dp

Post a Comment for "Confusion In "smallest Width Dp" In Android"