I am developing for Android and I ran into a problem. When I use addView
method of ViewGroup
to add a ViewGroup
object, it does not display anything on the screen.
Can anyone help me?
RelativeLayout fullLayout=new RelativeLayout(this);
RelativeLayout top=new RelativeLayout(this);
TextView phoneNumber=new TextView(context);
phoneNumber.setText("137928833");
RelativeLayout.LayoutParams phoneParams=new RelativeLayout.LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT);
phoneParams.addRule(RelativeLayout.ALIGN_PARENT_LEFT); phoneParams.leftMargin=130; phoneParams.topMargin=120;
top.addView(phoneNumber,phoneParams);
fullLayout.addView(top,0);
I use setContentView(fullLayouot),it does not work.