2024-07-08
한어Русский языкEnglishFrançaisIndonesianSanskrit日本語DeutschPortuguêsΕλληνικάespañolItalianoSuomalainenLatina
Use TextView, Button, etc. to implement a calculator interface, as shown in Figure 1.
Figure 1 Calculator interface renderings
The overall interface uses a table layout. The first row uses a TextView control, spanning 4 columns, the middle 4 rows and 4 columns, and the first control in the last row spans 2 columns.
1) Create a new project, select "Empty Views Activity", specify the project name as Calucator, and the package name as cn.edu.jssvc.calucator.
2) Use linear layout to design the interface, open activity_mail.xml, switch to Code view, change the constraint layout (ConstraintLayout) in Code to table layout (TableLayout), delete the controls in it, and set the attribute android:stretchColumns="0,1,2,3" of the TableLayout.
3) Drag TableRow from the Palette area to the Component Tree and set the TableRow attribute android:layout_weight="1" so that the five rows divide the entire screen equally, as shown in Figures 2 and 3.
Figure 2 TableRow settings
Figure 3 TableRow property settings
4) Drag the TextView control into the first row and set its android:layout_span attribute to 4, that is, spanning 4 columns: