Android Layout Framelayout

Source: Internet
Author: User

1 Framelayout Introduction

For Framelayout, the official introduction is:
Framelayout is designed to block out an area on the screen to display a single item. Generally, framelayout should be-used to-hold a single child view, because it can be difficult to organize child views in A by that's scalable to different screens sizes without the children overlapping each other. Can, however, add multiple children to a framelayout and control their position within the framelayout by assigning GR Avity to all child, using the Android:layout_gravity attribute.

That is, the framelayout is designed to display a single item widget. In general, it is not recommended to use Framelayout to display multiple items, because their layouts are difficult to adjust. Multiple items overlap without the layout_gravity attribute, and you can set different positions if you use layout_gravity. Layout_gravity can use the following values:

Top
Places the object at the top of its container without changing its size.

Bottom
Places the object at the bottom of its container, without changing its size.

Left
Places the object on the left side of its container without changing its size.

Right
Places the object on the right side of its container without changing its size.

Center_vertical
Centers the object vertically without changing its size.
Vertical alignment: Center-aligned vertically.

Fill_vertical
When necessary, increase the vertical size of the object to fully fill its container.
Vertical fill

Center_horizontal
Centers the object horizontally, without changing its size.
Horizontal alignment: Center aligned horizontally

Fill_horizontal
When necessary, increase the horizontal size of the object to fully fill its container.
Fill horizontally

Center
Centers the object horizontally, without changing its size.

Fill
When necessary, increase the cross-portrait size of the object to fully fill its container.

Clip_vertical
Additional options for cutting the contents of the top and/or bottom of the object according to the edges of the container. Clipping is based on its vertical alignment settings: When the top is aligned, the bottom is clipped, the top is clipped at the bottom, and the top and bottom are cut apart.
Crop vertically

Clip_horizontal
An additional option to cut the contents of the left and/or right of the object according to the edges of the container. Clipping is based on its horizontal alignment settings: Cut to the right when left aligned, cut to the left when aligned to the right, and cut to the left and right.
Horizontal Orientation Clipping


Note: differentiate between "android:gravity" and "android:layout_gravity".
android:gravity : Is for the control itself, is used to set "the contents of the control itself" should be displayed in the "Control itself volume" where the default value is the left.
android:layout_gravity: Is relative to the control's parent element, setting where the control is located in its parent element.

2 Framelayout Example

Create an activity that contains 2 sets of framelayout:1 groups to set the Android:layout_gravity property, and the other 1 groups do not set the Android:layout_gravity property.

Layout file

<?XML version= "1.0" encoding= "Utf-8"?><LinearLayoutxmlns:android= "Http://schemas.android.com/apk/res/android"Android:layout_width= "Fill_parent"Android:layout_height= "Fill_parent"android:orientation= "vertical" >        <!--Example 1 framelayout content overlap -    <TextViewAndroid:text= "Example 1, framelayout content overlap"Android:layout_width= "Wrap_content"Android:layout_height= "Wrap_content"        />    <FramelayoutAndroid:layout_width= "300DP"Android:layout_height= "80DP" >        <TextViewAndroid:layout_width= "Wrap_content"Android:layout_height= "Wrap_content"Android:text= "I am TextView, the content is longer"Android:background= "#ff0000"/>        <ButtonAndroid:layout_width= "Wrap_content"Android:layout_height= "Wrap_content"Android:background= "#ffff00"Android:text= "I am the button"/>            </Framelayout>            <!--Example 2 framelayout using the Layout_gravity property -    <TextViewAndroid:text= "Example 2, setting layout_gravity"Android:layout_width= "Wrap_content"Android:layout_height= "Wrap_content"        />    <FramelayoutAndroid:layout_width= "300DP"Android:layout_height= "120DP" >        <TextViewAndroid:layout_width= "Wrap_content"Android:layout_height= "Wrap_content"Android:text= "Text left"Android:background= "#ff0000"android:gravity= "Center"android:layout_gravity= "Left"Android:layout_margin= "10DP"/>        <TextViewAndroid:layout_width= "Wrap_content"Android:layout_height= "Wrap_content"Android:text= "Text centered"Android:background= "#ffff00"android:gravity= "Center"android:layout_gravity= "Center"/>    </Framelayout></LinearLayout>

Android Layout Framelayout

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.