Learn about Android for a while and now start working on a small example-calculator. I believe we have calculators in our phones, but do you know how it's done? In fact, I still do not know, now on the simple layout to do a small summary.
For a software , a nice user interface (UI) can always impress users, which is what we should be thinking after the interface design lesson. For mobile applications such as Android, the user interface is not negligible. In Android ,View is the base class for all visual controls, and it has five main layouts:
Linear layout
Linear layout (LinearLayout) is a simpler layout that provides a horizontal or vertical arrangement of controls.
Table layout
table Layouts (tablelayout) organize the layout of child views by row and column, including a series of TableRow formation, used to define rows.
Relative layout
Relative layout (relativelayout) means that child elements inside a container can be positioned relative to each other or to a relative position between the containers.
Frame layout
Frame layout (framelayout) is the simplest layout in the five layouts, in which the entire interface is treated as an empty space, and all child elements cannot be assigned position placement, all placed in the upper left corner of the empty area, and the subsequent child elements are directly overlaid on the preceding child elements. Partially or completely obscures the preceding child elements.
Absolute layout
Absolute layout (absolutelayout) means that the arrangement of all controls is specified by the developer through the coordinates of the control, and the container is not responsible for managing the location of the child controls.
it says it. Android five layouts, the developer chooses the layout according to the requirements of the interface when the actual design is carried out. In addition, the five layouts can also be nested with each other. The following is an example of an interface for designing an Android computer, with a nested nesting of layouts. Modify
Master Activity the layout file Main.xml , the code is as follows:
<?xml version= "1.0" encoding= "Utf-8"? ><linearlayout xmlns:android= "http://schemas.android.com/apk/res/ Android "Android:layout_width=" Fill_parent "android:layout_height=" fill_parent "android:orientation=" vertical "&G T <textview android:layout_width= "fill_parent" android:layout_height= "Wrap_content" android:text= "the case Example Demo layout nesting "android:textsize=" 20px "/> <textview android:layout_width=" Fill_parent "Androi d:layout_height= "50px" android:textsize= "40px" android:gravity= "right" android:background= "#fff"/> <relativelayout android:layout_width= "fill_parent" android:layout_height= "Wrap_content" Android:o rientation= "Horizontal" > <button android:id= "@+id/num1" android:layout_width= " Wrap_content "android:layout_height=" Wrap_content "android:layout_alignparentleft=" true " Android:padding= "20px" android:text= "1" android:textsize= "20px"/> <button android:id= "@+id/num2" Android:layout_width= "Wrap_content" android:layout_height= "Wrap_content" Android:layout_torighto f= "@id/num1" android:padding= "20px" android:text= "2" android:textsize= "20px"/> <button android:id= "@+id/num3" android:layout_width= "Wrap_content" Android:layout_hei ght= "Wrap_content" android:layout_torightof= "@id/num2" android:padding= "20px" Android:tex t= "3" android:textsize= "20px"/> <button android:id= "@+id/back" Android Oid:layout_width= "Wrap_content" android:layout_height= "wrap_content" android:layout_torightof= "@id/N Um3 "android:padding=" 20px "android:text=" Back "android:textsize=" 20px "/> < Button AndroiD:id= "@+id/add" android:layout_width= "wrap_content" android:layout_height= "Wrap_content" android:layout_torightof= "@id/back" android:padding= "20px" android:text= "+" android:texts Ize= "20px"/> </RelativeLayout> <relativelayout android:layout_width= "fill_parent "Android:layout_height=" wrap_content "android:orientation=" Horizontal "> <button Android:id= "@+id/num11" android:layout_width= "wrap_content" android:layout_height= "Wrap_conten T "android:layout_below=" @id/num1 "android:padding=" 20px "android:text=" 4 "and Roid:textsize= "20px"/> <button android:id= "@+id/num12" android:layout_width= "Wrap_cont Ent "android:layout_height=" wrap_content "android:layout_torightof=" @id/num11 "Android:pa Dding= "20px"android:text= "5" android:textsize= "20px"/> <button android:id= "@+id/num13" Android:layout_width= "Wrap_content" android:layout_height= "wrap_content" android:layout_torightof= "@ Id/num12 "android:padding=" 20px "android:text=" 6 "android:textsize=" 20px "/> <button android:id= "@+id/left" android:layout_width= "Wrap_content" android:layou t_height= "Wrap_content" android:layout_torightof= "@id/num13" android:padding= "20px" Andro Id:text= "(" android:textsize= "20px"/> <button android:id= "@+id/jian" Androi D:layout_width= "Wrap_content" android:layout_height= "wrap_content" android:layout_torightof= "@id/lef T "android:padding=" 20px "android:text="-"android:textsize=" 20px "/> </ Relativelayout> <relativelayout android:layout_width= "fill_parent" android:layout_height= "Wrap_content" android:orientation= "Horizontal" > <button android:id= "@+id/num21" Android:layo Ut_width= "Wrap_content" android:layout_height= "wrap_content" android:layout_below= "@id/num11" android:padding= "20px" android:text= "7" android:textsize= "20px"/> <button Android:id= "@+id/num22" android:layout_width= "wrap_content" android:layout_height= "Wrap_content" android:layout_torightof= "@id/num21" android:padding= "20px" android:text= "8" Android:textsize= "20px"/> <button android:id= "@+id/num23" android:layout_width= "Wrap_c Ontent "android:layout_height=" wrap_content "android:layout_torightof=" @id/num22 "Android :p adding= "20px" android:text= "9" android:textsize= "20px"/> <button android:id= "@+id/right" Android:layout_width= "Wrap_content" android:layout_height= "Wrap_content" android:layout_t orightof= "@id/num23" android:padding= "20px" android:text= ")" android:textsize= "20px"/> ; <button android:id= "@+id/chen" android:layout_width= "Wrap_content" Android:layout_heig ht= "Wrap_content" android:layout_torightof= "@id/right" android:padding= "20px" Android:tex t= "*" android:textsize= "20px"/> </RelativeLayout> <relativelayout Android:lay Out_width= "Fill_parent" android:layout_height= "wrap_content" android:orientation= "Horizontal" > <button android:id= "@+id/num31" android:layout_width= "Wrap_content" Android:layo ut_height= "Wrap_content "android:layout_below=" @id/num21 "android:padding=" 20px "android:text=" 0 " Android:textsize= "20px"/> <button android:id= "@+id/num32" Android:layout_width= "W Rap_content "android:layout_height=" wrap_content "android:layout_torightof=" @id/num31 "an droid:padding= "20px" android:text= "CE" android:textsize= "20px"/> <button an Droid:id= "@+id/num33" android:layout_width= "wrap_content" android:layout_height= "Wrap_content" android:layout_torightof= "@id/num32" android:padding= "20px" android:text= "." Android:textsize= "20px"/> <button android:id= "@+id/equal" android:layout_width = "Wrap_content" android:layout_height= "wrap_content" android:layout_torightof= "@id/num33" Android:padding= "20px" android:text= "=" android:textsize= "20px"/> <button android:id= "@+id/gang" Android:layout_width= "Wrap_content" android:layout_height= "Wrap_content" Android:layout_torighto f= "@id/equal" android:padding= "20px" android:text= "/" android:textsize= "20px"/> </RelativeLayout></LinearLayout>
As follows:
The layout of the Android development calculator