Layout Manager for Android

Source: Internet
Author: User

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.

 

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.