I have to implement layout like this; The layout should wrap the content if the content within it is less. If the content goes beyond some size, like 300dp, it should be set to max heght(300dp) and that be able to scroll. Is there any properties to do like this, if not any workaround?
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With