In theory, you can set a view to activity by Setcontentview (view), but when you have a lot of view controls, you need to use the Android layout manager to manage the view controls.
The Android layout manager is available in the following ways:
1. Linear Layout LinearLayout
2. Frame Layout Framelayout
3. Table Layout Tablelayout
4. Relative Layout relativelayout
5. Absolute layout absolutelayout
One, LinearLayout linear layout Manager
The linear layout is divided into two types: horizontal layout and vertical layout. Horizontal layout is the view horizontal arrangement, through Layout.setorientation (linearlayout.horizontal), vertical is the view vertical arrangement, through layout.setorientation ( linearlayout.vertical) to achieve.
Public classMainactivityextendsactionbaractivity {@Overrideprotected voidonCreate (Bundle savedinstancestate) {Super. OnCreate (savedinstancestate); LinearLayout lly=NewLinearLayout ( This); Linearlayout.layoutparams LLP=Newlinearlayout.layoutparams (ViewGroup.LayoutParams.MATCH_PARENT, Viewgroup.layoutparams. Match_parent); Lly.setorientation (linearlayout.vertical); Setcontentview (Lly, LLP); Linearlayout.layoutparams Viewparams=Newlinearlayout.layoutparams (ViewGroup.LayoutParams.MATCH_PARENT, Viewgroup.layoutparams . Wrap_content); TextView TV1=NewTextView ( This); Tv1.settext ("This is Text1"); Tv1.setbackgroundcolor (Color.rgb (0, 255, 30)); TextView TV2=NewTextView ( This); Tv2.settext ("This is Text2"); Tv2.setbackgroundcolor (Color.rgb (255, 30, 60)); Lly.addview (Tv1,viewparams); Lly.addview (Tv2,viewparams); } }
The Layoutparams LLP in the upper code is to ensure that the lly layout fills the entire screen at setcontentview time, while the second Layoutparams Viewparams to allow the controls inside the lly to keep the length filled lly Height of the control itself, finally through the AddView (view, params), through the experiment found that the params is not set here, the direct addview (view) effect is the same, are long fill, high control height.
Second, Framelayout framework layout Manager
This feeling is not much of a function, Framelayout is to put all the controls inside the layout in the upper left corner, and cover them one by one.