A working sample below (it's LayoutParams.WRAP_CONTENT, NOT LinearLayout.WRAP_CONTENT)
myLayout.setOrientation(LinearLayout.VERTICAL);
LinearLayout.LayoutParams layoutParams = new LinearLayout.LayoutParams(LayoutParams.WRAP_CONTENT,LayoutParams.WRAP_CONTENT);
myLayout.setLayoutParams(layoutParams);