Help.I found the height of ListView and I do not know px or dpi? I need dpi
final ListView actualListView = mPullRefreshListView.getRefreshableView();
actualListView.getViewTreeObserver().addOnGlobalLayoutListener(
new ViewTreeObserver.OnGlobalLayoutListener() {
public void onGlobalLayout() {
height = actualListView.getHeight();
}
});
There are two options to convert px to dpi: Automatically, using the online converter above to easily and quickly convert pixel to dpi. Manually, using the following formula: DPI = Diagonal In Pixels/Diagonal In Inches
In general, photo quality is considered to be a 200 DPI scan at actual size. Consider using a higher scan DPI if you plan to enlarge or reprint an image. Since we are talking about images and image quality, it is important to note how all of this relates to what might be the most well-known form of a pixel – the megapixel.
The conversion of dp units to screen pixels is simple: px = dp * (dpi / 160). For example, on a 240 dpi screen, 1 dp equals 1.5 physical pixels. You should always use dp units when defining your application's UI, to ensure proper display of your UI on screens with different densities
To print this image at its highest quality which is at 150 DPI, the image comprised of 3000x2400 pixels must be printed at a size of 3000 px ÷ 150 dpi = 20 inches wide by 2400 px ÷ 150 dpi = 16 inches high. One thing to note for simplicity sake, our examples with 150DPI are for large format printing.
getheight return height in pixels, Below is what docs says..
public final int getHeight ()
Since: API Level 1
Return the height of your view. Returns
The height of your view, in pixels.
You need to convert px into dp , use below ways to convert it to dp.
Convert pixel to dp:
public int pxToDp(int px) {
DisplayMetrics displayMetrics = getContext().getResources().getDisplayMetrics();
int dp = Math.round(px / (displayMetrics.xdpi / DisplayMetrics.DENSITY_DEFAULT));
return dp;
}
or if you want it in px use below.
Convert dp to pixel:
public int dpToPx(int dp) {
DisplayMetrics displayMetrics = getContext().getResources().getDisplayMetrics();
int px = Math.round(dp * (displayMetrics.xdpi / DisplayMetrics.DENSITY_DEFAULT));
return px;
}
It returns pixels. http://developer.android.com/reference/android/view/View.html#getHeight() To convert pixels to dpi use this formula px = dp * (dpi / 160)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With