How to set the max height of a Layout in android?
You can find the display size of the device. according to the display size you can set layout params
. for example, if the display size is less than 300dp
, you can set height
as wrap content
. if more than 300dp
means set height
as 300dp
.
here is the example code:
WindowManager wm = (WindowManager) ctx.getSystemService(Context.WINDOW_SERVICE); DisplayMetrics metrics = new DisplayMetrics(); wm.getDefaultDisplay().getMetrics(metrics); //here you can get height of the device. Log.d("check", metrics.heightPixels+""); if(metrics.heightPixels< 300) { this.getWindow().setLayout(LayoutParams.WRAP_CONTENT,LayoutParams.WRAP_CONTENT); } else { this.getWindow().setLayout(LayoutParams.WRAP_CONTENT,300); }
hope this one can help you.