Android Learning lesson three-common layout

Source: Internet
Author: User

1. Relative layout

Simply put, by describing where each component is located, the Layout_below used, and so on, is the control of the position relationship between the component and the component.

2. Absolute layout

is to determine the location by describing his x, y coordinates.

3. Linear layout

There are two types that are horizontal and vertical, and generally use linear layouts to arrange a multitude of components

3. Frame layout

I feel like a layer of layers, by default, multiple components are in the same location, so you need to modify the location. You can also choose whether or not to display.

This can be used to describe the control method of the video player pause key.

The code is as follows.

<?XML version= "1.0" encoding= "Utf-8"?><Framelayoutxmlns:android= "Http://schemas.android.com/apk/res/android"Android:layout_width= "Match_parent"Android:layout_height= "Match_parent" >    <TextViewAndroid:layout_width= "Match_parent"Android:layout_height= "Match_parent"android:gravity= "Center"Android:text= "I am the video player, I am playing the text"android:visibility= "visible"        />    <LinearLayoutAndroid:layout_width= "Match_parent"Android:layout_height= "Match_parent"android:gravity= "Center"        >    <ImageViewAndroid:id= "@+id/iv"Android:layout_width= "Wrap_content"Android:layout_height= "Wrap_content"android:gravity= "Center"android:src= "@drawable/ic_launcher"android:visibility= "Invisible"        />    </LinearLayout><LinearLayoutAndroid:layout_width= "Match_parent"Android:layout_height= "Match_parent"android:orientation= "Horizontal" >    <ButtonAndroid:id= "@+id/button1"Android:layout_width= "Wrap_content"Android:layout_height= "Wrap_content"Android:text= "Play"Android:onclick= "Play"/>    <ButtonAndroid:id= "@+id/button2"Android:layout_width= "Wrap_content"Android:layout_height= "Wrap_content"Android:text= "Pause"Android:onclick= "Pause"/></LinearLayout></Framelayout>
 Packagecom.example.layout;Importandroid.app.Activity;ImportAndroid.os.Bundle;ImportAndroid.view.View;ImportAndroid.widget.ImageView; Public classMainactivityextendsActivity { PublicImageView IV; @Overrideprotected voidonCreate (Bundle savedinstancestate) {Super. OnCreate (savedinstancestate);        Setcontentview (R.layout.frame); IV=(ImageView) Findviewbyid (R.ID.IV); }     Public voidPlay (View Ciew) {iv.setvisibility (view.invisible); }     Public voidPause (View ciew) {iv.setvisibility (view.visible); }}

The code is simple. However, frame layout and relative layout are used.

5. Network layout

The function of this is like a grid. The functionality of the Java GUI is the same.

The

summarizes these layouts, which can be analogous to several layout types in Javagui.

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.