Android self-taught absolute layout absolutelayout

Source: Internet
Author: User

Absolute Layout (absolutelayout), the absolute layout is like the empty layout in Java AWT, the so-called absolute layout is that Android does not provide any layout control, but the developers themselves through the x-coordinate and the y-coordinate to control the position of the component. When using an absolute layout as a layout container, the layout container does not manage the location of the sub-containers, which require the developer's own control.

When using an absolute layout, each component can use these two XML attributes

Layout_x: Specifies the x-coordinate of the subassembly;

Layout_y: Specifies the y-coordinate of the subassembly;

Take an example of learning:

Layout/main.xml

1 <?XML version= "1.0" encoding= "Utf-8"?>2 <Absolutelayoutxmlns:android= "Http://schemas.android.com/apk/res/android"3 android:orientation= "vertical"4 Android:layout_width= "Fill_parent"5 Android:layout_height= "Fill_parent"6     >7 <!--Define a text box, using absolute positioning -8 <TextView9     android:layout_x= "20dip"Ten android:layout_y= "20dip" One Android:layout_width= "Wrap_content"  A Android:layout_height= "Wrap_content"  - Android:text= "User name:" -     /> the <!--Define a text edit box, using absolute positioning - - <EditText -      android:layout_x= "80dip"  -  android:layout_y= "15dip"  + Android:layout_width= "Wrap_content"  - Android:width= "200px"  + Android:layout_height= "Wrap_content"  A     /> at <!--Define a text box, using absolute positioning -     - <TextView -     android:layout_x= "20dip" - android:layout_y= "80dip" - Android:layout_width= "Wrap_content"  - Android:layout_height= "Wrap_content"  in Android:text= "Password:" -     /> to <!--Define a text edit box, using absolute positioning -     + <EditText -     android:layout_x= "80dip" the android:layout_y= "75dip" * Android:layout_width= "Wrap_content"  $ Android:width= "200px" Panax Notoginseng Android:layout_height= "Wrap_content"  - Android:password= "true" the     /> + <!--Define a button that uses absolute positioning - A <Button the     android:layout_x= "130dip" + android:layout_y= "135dip" - Android:layout_width= "Wrap_content"  $ Android:layout_height= "Wrap_content"  $ Android:text= "Login" -     />     - </Absolutelayout>

The above code shows:

Main program

Com.example.absolutelayouttest.MainActivity.java

1  Packagecom.example.absolutelayouttest;2 3 Importandroid.support.v7.app.ActionBarActivity;4 ImportAndroid.support.v7.app.ActionBar;5 Importandroid.support.v4.app.Fragment;6 ImportAndroid.os.Bundle;7 ImportAndroid.view.LayoutInflater;8 ImportAndroid.view.Menu;9 ImportAndroid.view.MenuItem;Ten ImportAndroid.view.View; One ImportAndroid.view.ViewGroup; A ImportAndroid.os.Build; -  -  Public classMainactivityextendsactionbaractivity { the  - @Override -     protected voidonCreate (Bundle savedinstancestate) { -         Super. OnCreate (savedinstancestate); + Setcontentview (r.layout.main); -  +          A     } at  -}

The main program above just shows the Layout/main.xml layout.

Layout/main.xml the android:layout_x, android:layout_y properties of each component specified in the interface layout specify a property value that is shaped like 20dip.

The following commonly used distance units are generally supported in Android:

    1. PX (pixels): Each pixel corresponds to a point on the screen.
    2. Dip or DP (device independent pixels, unit-independent pixels): An abstract unit based on screen density. For example: On a 160-point display per inch, 1dip=1px. However, as the screen density changes, the dip and PX conversion will change.
    3. SP (scaled pixels, proportional pixels): Primarily handles font size, which can be scaled based on the user's font size preference.
    4. In (inches): standard length units.
    5. MM (mm): standard length unit.
    6. PT (LB): standard length unit, 1/72 inch.

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.