Chapter 3 UI cornerstone-UI layout (3)

Source: Internet
Author: User

Chapter 3 UI cornerstone-UI layout (3)
3.2.4 frame layout (FrameLayout)

FrameLayout is the simplest layout in the five la S, also known as layer layout or frame layout. In this layout, the entire interface is treated as a blank standby area. All child elements cannot be placed in the specified position. They are placed in the upper left corner of the area and arranged in layers. The layout cannot control the size and position of the Child control, but the child control can control its size and position. The next child element directly overwrites the previous child element and blocks them in part or whole (unless the last child element is transparent ). This layout is usually used for games or for some gallery programs.

We also give a simple example.

<? Xml version = "1.0" encoding = "UTF-8"?>

<FrameLayout

Xmlns: android = "http://schemas.android.com/apk/res/android"

Android: orientation = "vertical"

Android: layout_width = "match_parent"

Android: layout_height = "match_parent">

<TextView

Android: layout_width = "200dp"

Android: layout_height = "200dp"

Android: background = "@ android: color/white"

Android: gravity = "bottom | center_horizontal"

Android: text = "text"

Android: textColor = "@ android: color/black"/>

<ImageView

Android: layout_width = "100dp"

Android: layout_height = "100dp"

Android: background = "@ drawable/icon"/> \

<Button

Android: layout_width = "wrap_content"

Android: layout_height = "wrap_content"

Android: text = "OK"/>

</FrameLayout>

 

See Figure 3-6.

Figure 3-6 framelayout framework layout (1)

 

We can see that these controls are all stacked in the upper left corner, and cover one layer. Next, let's change their location through the layout_gravity attribute.

<? Xml version = "1.0" encoding = "UTF-8"?>

<FrameLayout

Xmlns: android = "http://schemas.android.com/apk/res/android"

Android: orientation = "vertical"

Android: layout_width = "match_parent"

Android: layout_height = "match_parent">

<TextView

Android: layout_width = "200dp"

Android: layout_height = "200dp"

Android: background = "@ android: color/white"

Android: layout_gravity = "right"

Android: gravity = "bottom | center_horizontal"

Android: text = "text"

Android: textColor = "@ android: color/black"/>

<ImageView

Android: layout_width = "100dp"

Android: layout_height = "100dp"

Android: layout_gravity = "center_horizontal"

Android: background = "@ drawable/icon"/>

<Button

Android: layout_width = "wrap_content"

Android: layout_height = "wrap_content"

Android: layout_gravity = "center_horizontal"

Android: layout_marginTop = "20dp"

Android: text = "OK"/>

</FrameLayout>

 

The effect is 3-7.

Figure 3-7 framelayout framework layout (2)


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.