I am trying to change linear layout or any other widget width or height dynamically but throwing exception.
My layout is:
You can use this method inside your utils class to set height and width dynamically.
public void setWidthAndHeight(Context context,RelativeLayout view,int width, int height) {
width = (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, width, context.getResources().getDisplayMetrics());//used to convert you width integer value same as dp
height = (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, height, context.getResources().getDisplayMetrics());
//note : if your layout is LinearLayout then use LinearLayout.LayoutParam
view.setLayoutParams(new RelativeLayout.LayoutParams(width, height));
}