/res/layout/main.xml
  1. <?xml version="1.0" encoding="utf-8"?>
  2. <-- Use ScrollView to allow application to have automatic
  3.     scrollablility when phone is in landscape mode -->
  4. <ScrollView
  5.         android:id="@+id/ScrollView01"
  6.         android:layout_width="fill_parent"
  7.         android:layout_height="fill_parent"
  8.         xmlns:android="http://schemas.android.com/apk/res/android">
  9. <!-- Using table layout to have HTML table like control over layout -->
  10. <TableLayout
  11.         android:id="@+id/TableLayout01"
  12.         android:layout_width="fill_parent"
  13.         android:layout_height="fill_parent"
  14.         android:stretchColumns="1"
  15.         xmlns:android="http://schemas.android.com/apk/res/android">
  16.     <!-- Row 1: Text label placed in column zero,
  17.          text field placed in column two and allowed to
  18.          span two columns. So a total of 4 columns in this row -->
  19.         <TableRow>
  20.         <TextView
  21.                 android:id="@+id/txtLbl1"
  22.                 android:layout_width="wrap_content"
  23.                 android:layout_height="wrap_content"
  24.                 android:layout_column="0"
  25.                 android:text="@string/textLbl1"/>
  26.         <EditText
  27.                 android:id="@+id/txtAmount"
  28.                 android:layout_width="wrap_content"
  29.                 android:layout_height="wrap_content"
  30.                 android:numeric="decimal"
  31.                 android:layout_column="2"
  32.                 android:layout_span="2"
  33.                 />                     
  34.         </TableRow>
  35.     <!-- Row 2: Text label placed in column zero,
  36.          text field placed in column two and allowed to
  37.          span two columns. So a total of 4 columns in this row -->
  38.         <TableRow>
  39.         <TextView
  40.                 android:id="@+id/txtLbl2"
  41.                 android:layout_width="wrap_content"
  42.                 android:layout_height="wrap_content"
  43.                 android:layout_column="0"
  44.                 android:text="@string/textLbl2"/>
  45.         <EditText
  46.                 android:id="@+id/txtPeople"
  47.                 android:layout_width="wrap_content"
  48.                 android:layout_height="wrap_content"
  49.                 android:numeric="integer"
  50.                 android:layout_column="2"
  51.                 android:layout_span="3"/>                      
  52.         </TableRow>
  53.    <!-- Row 3: This has just one text label placed in column zero  -->
  54.         <TableRow>
  55.         <TextView
  56.                 android:id="@+id/txtLbl3"
  57.                 android:layout_width="wrap_content"
  58.                 android:layout_height="wrap_content"
  59.                 android:text="@string/textLbl3"/>
  60.         </TableRow>    
  61.    <!-- Row 4: RadioGroup for RadioButtons placed at column zero
  62.         with column span of three, thus creating one radio button
  63.         per cell of the table row. Last cell number 4 has the
  64.         textfield to enter a custom tip percentage -->
  65.         <TableRow>     
  66.         <RadioGroup
  67.                 android:id="@+id/RadioGroupTips"
  68.                 android:orientation="horizontal"
  69.                 android:layout_width="wrap_content"
  70.                 android:layout_height="wrap_content"
  71.                 android:layout_column="0"
  72.                 android:layout_span="3"
  73.                 android:checkedButton="@+id/radioFifteen">
  74.                 <RadioButton android:id="@+id/radioFifteen"
  75.                         android:layout_width="wrap_content"
  76.                         android:layout_height="wrap_content"
  77.                         android:text="@string/rdoTxt15"
  78.                         android:textSize="15sp" />
  79.                 <RadioButton android:id="@+id/radioTwenty"
  80.                         android:layout_width="wrap_content"
  81.                         android:layout_height="wrap_content"
  82.                         android:text="@string/rdoTxt20"
  83.                         android:textSize="15sp" />
  84.                 <RadioButton android:id="@+id/radioOther"
  85.                         android:layout_width="wrap_content"
  86.                         android:layout_height="wrap_content"
  87.                         android:text="@string/rdoTxtOther"
  88.                         android:textSize="15sp" />
  89.         </RadioGroup>
  90.                 <EditText
  91.                         android:id="@+id/txtTipOther"
  92.                         android:layout_width="fill_parent"
  93.                         android:layout_height="wrap_content"
  94.                         android:numeric="decimal"/>                    
  95.         </TableRow>
  96.    <!--  Row for the Calculate and Rest buttons. The Calculate button
  97.          is placed at column two, and Reset at column three -->         
  98.         <TableRow>
  99.         <Button
  100.                 android:id="@+id/btnReset"
  101.                 android:layout_width="wrap_content"
  102.                 android:layout_height="wrap_content"
  103.                 android:layout_column="2"  
  104.                 android:text="@string/btnReset"/>
  105.         <Button
  106.                 android:id="@+id/btnCalculate"
  107.                 android:layout_width="wrap_content"
  108.                 android:layout_height="wrap_content"
  109.                 android:layout_column="3"
  110.                 android:text="@string/btnCalculate"/>
  111.         </TableRow>    
  112.  
  113.     <!-- TableLayout allows any other views to be inserted between
  114.          the TableRow elements. So inserting a blank view to create a
  115.          line separator. This separator view is used to separate
  116.          the area below the buttons which will display the
  117.          calculation results -->
  118.         <View
  119.                 android:layout_height="2px"
  120.                 android:background="#DDFFDD"
  121.                 android:layout_marginTop="5dip"
  122.                 android:layout_marginBottom="5dip"/>
  123.  
  124.     <!-- Again table row is used to place the result textviews
  125.          at column zero and the result in textviews at column two -->
  126.         <TableRow android:paddingBottom="10dip" android:paddingTop="5dip">
  127.         <TextView
  128.                 android:id="@+id/txtLbl4"
  129.                 android:layout_width="wrap_content"
  130.                 android:layout_height="wrap_content"
  131.                 android:layout_column="0"
  132.                 android:text="@string/textLbl4"/>
  133.         <TextView
  134.                 android:id="@+id/txtTipAmount"
  135.                 android:layout_width="wrap_content"
  136.                 android:layout_height="wrap_content"
  137.                 android:layout_column="2"
  138.                 android:layout_span="2"/>                      
  139.         </TableRow>
  140.        
  141.         <TableRow android:paddingBottom="10dip" android:paddingTop="5dip">
  142.         <TextView
  143.                 android:id="@+id/txtLbl5"
  144.                 android:layout_width="wrap_content"
  145.                 android:layout_height="wrap_content"
  146.                 android:layout_column="0"
  147.                 android:text="@string/textLbl5"/>
  148.         <TextView
  149.                 android:id="@+id/txtTotalToPay"
  150.                 android:layout_width="wrap_content"
  151.                 android:layout_height="wrap_content"
  152.                 android:layout_column="2"
  153.                 android:layout_span="2"/>                      
  154.         </TableRow>
  155.        
  156.         <TableRow android:paddingBottom="10dip" android:paddingTop="5dip">
  157.         <TextView
  158.                 android:id="@+id/txtLbl6"
  159.                 android:layout_width="wrap_content"
  160.                 android:layout_height="wrap_content"
  161.                 android:layout_column="0"
  162.                 android:text="@string/textLbl6"/>
  163.         <TextView
  164.                 android:id="@+id/txtTipPerPerson"
  165.                 android:layout_width="wrap_content"
  166.                 android:layout_height="wrap_content"
  167.                 android:layout_column="2"
  168.                 android:layout_span="2"/>                      
  169.         </TableRow>
  170.     <!--  End of all rows and widgets -->  
  171. </TableLayout>
  172. </ScrollView>
  173.  
Tutorials