Android development calculator layout, android development Calculator

Source: Internet
Author: User

Android development calculator layout, android development Calculator

After learning about Android for a period of time, I am now taking a small example-calculator. I believe that our mobile phones all have the calculator software, but do you know how it operates? In fact, I do not know yet. Now I will make a summary of the simple layout.

For a piece of software, a beautiful User Interface (UI) can always impress users, which is what we should do after the interface design course. For mobile apps such as Android, the user interface cannot be ignored. In Android, View is the base class of all visual controls. It has five layout methods:



 

Linear Layout

LinearLayout is a simple layout that provides horizontal or vertical control arrangement.

Table Layout

Table layout (TableLayout) refers to the layout of child views by row and column. It contains a series of TableRow formations for defining rows.

Relative Layout

RelativeLayout refers to the fact that child elements in a container can be located using the relative positions between each other or between containers.

Frame Layout

Frame layout (FrameLayout) is the simplest layout in the five major la S. In this layout, the entire interface is regarded as a blank area, and all child elements cannot be placed at specified positions, all are placed in the upper left corner of the blank area, and the child elements that follow the blank area directly overwrite the child elements in the front, partially or completely block the child elements.

Absolute Layout

The absolute layout (AbsoluteLayout) refers to the arrangement of all controls specified by developers through the control coordinates, and containers are not responsible for managing the sub-control positions.


The five la s of Android are described above. during actual design, developers can select the corresponding Layout Based on the interface requirements. In addition, the five la s can be nested with each other. The following is an example of the design of the Android computer interface, using the nested layout. Modify

The layout file main. xml of the main Activity. 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"> <TextView android: layout_width = "fill_parent" android: layout_height = "wrap_content" android: text = "nested layout" android: textSize = "20px"/> <TextView android: layout_width = "fill_parent" android: layout_height = "50px" android: textSize = "40px" android: gravity = "right" android: background = "# fff"/> <RelativeLayout android: layout_width = "fill_parent" android: layout_height = "wrap_content" android: orientation = "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_toRightOf = "@ id/num1" android: padding = "20px" android: text = "2" android: textSize = "20px"/> <Button android: id = "@ + id/num3" android: layout_width = "wrap_content" android: layout_height = "wrap_content" android: layout_toRightOf = "@ id/num2" android: padding = "20px" android: text = "3" android: textSize = "20px"/> <Button android: id = "@ + id/back" android: layout_width = "wrap_content" android: layout_height = "wrap_content" android: layout_toRightOf = "@ id/num3" 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: textSize = "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_content" android: layout_below = "@ id/num1" android: padding = "20px" android: text = "4" android: textSize = "20px"/> <Button android: id = "@ + id/num12" android: layout_width = "wrap_content" android: layout_height = "wrap_content" android: layout_toRightOf = "@ id/num11" android: padding = "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: layout_height = "wrap_content" android: layout_toRightOf = "@ id/num13" android: padding = "20px" android: text = "(" android: textSize = "20px"/> <Button android: id = "@ + id/jian" android: layout_width = "wrap_content" android: layout_height = "wrap_content" android: layout_toRightOf = "@ id/left" 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: layout_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_content" android: layout_height = "wrap_content" android: layout_toRightOf = "@ id/num22" android: padding = "20px" android: text = "9" android: textSize = "20px"/> <Button android: id = "@ + id/right" android: layout_width = "wrap_content" android: layout_height = "wrap_content" android: layout_toRightOf = "@ id/num23" android: padding = "20px" android: text = ")" android: textSize = "20px"/> <Button android: id = "@ + id/chen" android: layout_width = "wrap_content" android: layout_height = "wrap_content" android: layout_toRightOf = "@ id/right" 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/num31" android: layout_width = "wrap_content" android: layout_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 = "wrap_content" android: layout_height = "wrap_content" android: layout_toRightOf = "@ id/num31" android: padding = "20px" android: text = "CE" android: textSize = "20px"/> <Button android: 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_toRightOf = "@ id/equal" android: padding = "20px" android: text = "/" android: textSize = "20px"/> </RelativeLayout> </LinearLayout>

As follows:





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.