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:
- PX (pixels): Each pixel corresponds to a point on the screen.
- 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.
- SP (scaled pixels, proportional pixels): Primarily handles font size, which can be scaled based on the user's font size preference.
- In (inches): standard length units.
- MM (mm): standard length unit.
- PT (LB): standard length unit, 1/72 inch.