LinearLayout home_fragment = (LinearLayout) findViewById(R.id.home_fragment);
LinearLayout.LayoutParams linearParams = (LinearLayout.LayoutParams) home_fragment.getLayoutParams();
home_fragment.getLayoutParams();
Log.i("mylog", "getDpi()"+getDpi());
Log.i("mylog", "getScreenShowHeight()"+getScreenShowHeight(this));
Log.i("mylog", "getScreenHeight()"+getScreenHeight(this));
if(getScreenShowHeight(this)!=getScreenHeight(this)){
if(getScreenHeight(this)==1280){
linearParams.height=getScreenHeight(this)-(getScreenHeight(this)-getScreenShowHeight(this))-200;
}else if(getScreenHeight(this)==1920){
linearParams.height=getScreenHeight(this)-(getScreenHeight(this)-getScreenShowHeight(this))-300;
}else if(getScreenHeight(this)==960){
linearParams.height=getScreenHeight(this)-(getScreenHeight(this)-getScreenShowHeight(this))-150;
}
}
home_fragment.setLayoutParams(linearParams);
fm = getSupportFragmentManager();
public static int getScreenShowHeight(Context context) {
WindowManager wm = (WindowManager) context
.getSystemService(Context.WINDOW_SERVICE);
return wm.getDefaultDisplay().getHeight();
}
private int getDpiqqq()
{
String dpi = null;
Display display = getWindowManager().getDefaultDisplay();
DisplayMetrics dm = new DisplayMetrics();
@SuppressWarnings("rawtypes")
Class c;
try
{
c = Class.forName("android.view.Display");
@SuppressWarnings("unchecked")
Method method = c.getMethod("getRealMetrics", DisplayMetrics.class);
method.invoke(display, dm);
dpi = dm.widthPixels + "*" + dm.heightPixels;
} catch (Exception e) {
e.printStackTrace();
}
return dm.heightPixels;
}
public int getScreenHeight(Context context) {
WindowManager wm = (WindowManager) context.getApplicationContext()
.getSystemService(Context.WINDOW_SERVICE);
boolean isRotation = false;
int rotation = wm.getDefaultDisplay().getRotation();
if (!(rotation == 3 || rotation == 1)) {
isRotation = true;
}
Point point = new Point();
if (VERSION.SDK_INT >= 17) {
wm.getDefaultDisplay().getRealSize(point);
return isRotation ? point.y : point.x;
} else {
try {
return ((Integer) (isRotation != true ? Display.class
.getMethod("getRawWidth", new Class[0]) : Display.class
.getMethod("getRawHeight", new Class[0])).invoke(
wm.getDefaultDisplay(), new Object[0])).intValue();
} catch (Exception e) {
if (VERSION.SDK_INT >= 13) {
wm.getDefaultDisplay().getSize(point);
return isRotation ? point.y : point.x;
}
else {
return getDpiqqq();
}
}
}
}