Java tutorial
//package com.java2s; import android.annotation.SuppressLint; import android.graphics.Point; import android.os.Build; import android.view.Display; import android.view.WindowManager; public class Main { public static float getScaledWidth(WindowManager windowManager, float baseY, float basex, int exceptDis) { final Display display = windowManager.getDefaultDisplay(); Point mPoint = new Point(); getSize(display, mPoint); if (exceptDis > mPoint.x) { return 0.0f; } return mPoint.x - exceptDis; } @SuppressLint("NewApi") public static void getSize(Display display, Point outSize) { if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB) { display.getSize(outSize); } else { outSize.x = display.getWidth(); outSize.y = display.getHeight(); } } }