Android examples for User Interface:Screen Size
set Screen Size via LayoutParams
//package com.java2s; import android.app.Activity; import android.content.Context; import android.content.res.Configuration; import android.os.Build; import android.view.Display; import android.view.WindowManager; import android.view.WindowManager.LayoutParams; public class Main { public static void setSceenSize(Activity activity) { WindowManager m = activity.getWindowManager(); Display d = m.getDefaultDisplay(); LayoutParams p = activity.getWindow().getAttributes(); if (isPad(activity)) { p.height = (int) (d.getHeight() * 0.8); p.width = (int) (d.getWidth() * 0.5); }//from w w w . ja v a 2 s . co m p.alpha = 1.0f; p.dimAmount = 0.7f; activity.getWindow().setAttributes(p); } public static boolean isPad(Context applicationContext) { boolean isPad = false; // {treat Galaxy Note as phone.N7000 String model = Build.MODEL; if (model.contains("N7000") || model.contains("I9200") || model.contains("C6802") || model.contains("C6833")) { return false; } Configuration config = applicationContext.getResources() .getConfiguration(); if ((config.screenLayout & Configuration.SCREENLAYOUT_SIZE_MASK) == Configuration.SCREENLAYOUT_SIZE_NORMAL) { isPad = false; } else if ((config.screenLayout & Configuration.SCREENLAYOUT_SIZE_MASK) == Configuration.SCREENLAYOUT_SIZE_SMALL) { isPad = false; } else if ((config.screenLayout & Configuration.SCREENLAYOUT_SIZE_MASK) == 4) { isPad = true; } else { isPad = true; } return isPad; } }