Brief introduction
The relative layout of components is determined by the sibling component and the parent group price, so this layout is referred to as relative layout.
Introduction to property settings
The properties that can only be set to true and False in Relativelayout.layoutparam are:
Properties that need to depend on other component ID settings:
In addition to this, relativelayout can also use the properties of Viewgroup.marginlayoutparams.
Example of plum blossom layout
<linearlayout xmlns:android="Http://schemas.android.com/apk/res/android"xmlns:tools="Http://schemas.android.com/tools"Android:layout_width="Match_parent"android:layout_height="Match_parent"android:paddingleft="@dimen/activity_horizontal_margin"android:paddingright="@dimen/activity_horizontal_margin"android:paddingtop="@dimen/activity_vertical_margin"Android:paddingbottom="@dimen/activity_vertical_margin"tools:context=". Mainactivity "android:orientation="Vertical"> <relativelayout android:layout_width="Fill_parent"android:layout_height="Fill_parent"> <textview android:layout_width="Wrap_content"android:layout_height="Wrap_content"Android:background="@drawable/ic_launcher"Android:id="@+id/view01"Android:layout_centerinparent="true"/> <textview android:layout_width="Wrap_content"android:layout_height="Wrap_content"Android:background="@drawable/ic_launcher"android:layout_below="@id/view01"android:layout_alignleft="@id/view01"/> <textview android:layout_width="Wrap_content"android:layout_height="Wrap_content"Android:background="@drawable/ic_launcher"Android:layout_above="@id/view01"android:layout_alignleft="@id/view01"/> <textview android:layout_width="Wrap_content"android:layout_height="Wrap_content"Android:background="@drawable/ic_launcher"android:layout_toleftof="@id/view01"android:layout_aligntop="@id/view01"/> <textview android:layout_width="Wrap_content"android:layout_height="Wrap_content"Android:background="@drawable/ic_launcher"android:layout_torightof="@id/view01"android:layout_aligntop="@id/view01"/> </relativelayout></Linearlayout>
Table layout
GridLayout is a layout that was added after 4.0, dividing the space into rows*columns squares, where a component can set the number of columns and rows across.
Properties of the GridLayout
Common Properties:
Properties of the Gridlayout.layoutparam:
Example of the Calculator interface
Package Peng. Liu. TestView;Import Android. Annotation. Targetapi;Import Android. App. Activity;Import Android. OS. Build;Import Android. OS. Bundle;Import Android. OS. Handler;Import Android. OS. Message;Import Android. View. Gravity;Import Android. Widgets. Button;Import Android. Widgets. GridLayout;Import Android. Widgets. TextView;Import Java. Util. Timer;Import Java. Util. TimerTask;public class Mainactivity extends Activity {GridLayout Grid = null;string[] chars = new string[]{"7","8","9","/","4","5","6","*","1","2","3","-",".","0","+","+"};@TargetApi (Build. VERSION_codes. ICE_cream_sandwich) @Override protected void OnCreate (Bundle savedinstancestate) {Super. OnCreate(savedinstancestate);Setcontentview (R. Layout. Activity_main);Grid = (GridLayout) Findviewbyid (R. ID. Root);for (int i=0; i<chars.length;i++) {Button button = New button (this);button. SetText(Chars[i]);button. Settextsize( +);GridLayout. SpecRowspec = GridLayout. SpecI4+2);GridLayout. SpecColumnspec = GridLayout. Spec(i%4);GridLayout. Layoutparamsparams = new GridLayout. Layoutparams(ROWSPEC,COLUMNSPEC);Params. Setgravity(Gravity. FILL);Grid. AddView(Button,params);} }}
<LinearLayout xmlns:android="Http://schemas.android.com/apk/res/android" Xmlns:tools="Http://schemas.android.com/tools" Android:layout_width="Match_parent" Android:layout_height="Match_parent" Android:paddingleft="@dimen/activity_horizontal_margin" Android:paddingright="@dimen/activity_horizontal_margin" Android:paddingtop="@dimen/activity_vertical_margin" Android:paddingbottom="@dimen/activity_vertical_margin" Tools:context=". Mainactivity " android:orientation="Vertical"> <GridLayoutandroid:layout_width="Fill_parent"android:layout_height= "Fill_parent" android:id="@+id/root"android:rowcount="6"Android:columncount ="4"> <TextView Android:layout_width="Fill_parent" Android:layout_height="Wrap_content" Android:layout_columnspan="4" Android:layout_marginleft="4px" Android:layout_marginright="4px" android:padding="5px" android:textsize="50SP" android:layout_gravity="Right" Android:background="#eee" Android:textcolor="#000" Android:text="0"/> </GridLayout></linearlayout>
Absolute layout
Because of the absolute layout, the X position of the component and the Y position need to be set in person, so it is somewhat outdated.
Property
Android:layout_x: Sets the z-coordinate of the component
Android:layout_y: Sets the y-coordinate of the component
You can say that the relative layout is obsolete ~
Distance Unit Introduction
Android Layout-android Learning Journey (16)