En Android, hay varias formas de obtener la resolución de la pantalla
I. En la actividad
1.DisplayMetrics dm = getResources().getDisplayMetrics()
; int screenWidth = dm.widthPixels;
int screenHeight = dm.heightPixels;
2. DisplayMetrics dm = new DisplayMetrics();
this.getWindowManager() .getDefaultDisplay( ).getMetrics(dm);
int screenWidth = dm.widthPixels;
int screenHeight = dm.heightPixels;
2. En el servicio
DisplayMetrics dm = new DisplayMetrics();
dm = getResources().getDisplayMetrics()
int screenWidth = dm.widthPixels;
int screenHeight = dm.heightPixels;
3. Cuando esté inactivo, pase un contexto para llamar
1. public ImageGalleryAdapter(Context c) {
myContext = c;
DisplayMetrics dm = c.getResources().getDisplayMetrics();
int screenWidth = dm.widthPixels
int screenHeight = dm. heightPixels ;
2. public class BaseTools {
public static int getWindowWidth(Context context){
// Obtener la resolución de la pantalla
WindowManager wm = (WindowManager) (context.getSystemService(Context.WINDOW_SERVICE));
DisplayMetrics dm = new DisplayMetrics();
wm.getDefaultDisplay().getMetrics(dm)
int mScreenWidth = dm.widthPixels;