I have another class other than my main class, and inside this I want to add a layout programmatically with:
myLayo开发者_如何学Pythonut = new RelativeLayout(this);
But it crashes the app, why?
You need to add the layout params for the app. Right now your relative layout has no width or height.
ViewGroup.LayoutParams lp = new
LayoutParams(LayoutParams.FILL_PARENT,LayoutParams.FILL_PARENT);
myLayout = new RelativeLayout(this);
myLayout.setLayoutParams(lp);
This should work. if it doesnt put your stacktrace.
精彩评论