Java tutorial
//package com.java2s; import android.support.v4.app.Fragment; import android.util.DisplayMetrics; public class Main { public static <T extends Fragment> int getScreenWidth(T t) { DisplayMetrics metrics; t.getActivity().getWindowManager().getDefaultDisplay().getMetrics(metrics = new DisplayMetrics()); return metrics.widthPixels; } }