Found my own answer.
After trying a few things, I found that instead of:
myView.setLayoutParams(new LinearLayout.LayoutParams(100, 100));
I could use:
myView.layout(0, 0, 100, 100);
So the whole sample code would look like this:
public void testBitmap(){
LinearLayout l = new LinearLayout(getContext());
l.layout(0, 0, 100, 100);
MyCustomView myView = new MyCustomView(getContext());
myView.layout(0, 0, 100, 100);
l.addView(myView);
//draw things in myView
myView.getBitmap();
}