Eclipse Table Layout (ETL)


ETL:   SOLD       




TableLayout is a display that is arranged based on rows and columns. Usually, TableLayout consists of several TableRows. In this TableRow there are fields that will later be seen as columns. The final result of this section can be seen in Figure 3.6.


Figure 3.6

Let's get started!😃 

1. Run Enclipse, File > New > Android Project

2. Fill in the new dialog box as follows

| Project name     | LayoutTabel           |
|------------------|-----------------------|
| Build Target     | Android 2.2           |
| Application name | Tampilan Layout Tabel |
| Package name     | contoh.layoutTabel    |
| Create Activity  | LayoutTabel           |
| Min SDK version  | 8                     |

3. In Package Explorer, select LayoutTable > res > layout > main.xml then write the following xml

<?xml version="1.0" encoding="utf-8"?>
 <TableLayout xmlns:android="http://schemas.android.com/apk/res/android "
     android:layout_width="fill_parent"
     android:layout_height="fill_parent"
     android:stretchColumns="1">
     <TableRow>
         <TextView
             android:layout_column="1"
    android:text="Open..."
             android:padding="3dip" />
         <TextView
             android:text="Ctrl-O"
             android:gravity="right"
             android:padding="3dip" />
    </TableRow>
     <TableRow>
         <TextView
             android:layout_column="1"
             android:text="Save..."
             android:padding="3dip" />
        <TextView
             android:text="Ctrl-S"
             android:gravity="right"
             android:padding="3dip" />
    </TableRow>
     <TableRow>
         <TextView
             android:layout_column="1"
             android:text="Save As..."
             android:padding="3dip" />
         <TextView
             android:text="Ctrl-Shift-S"
             android:gravity="right"
             android:padding="3dip" />
    </TableRow>
     <View
         android:layout_height="2dip"
   android:background="#FF909090" />
     <TableRow>
         <TextView
             android:text="X"
             android:padding="3dip" />
         <TextView
             android:text="Import..."
             android:padding="3dip" />
 </TableRow>

Note that Figure 3.7 is a display of the hierarchy of a project.


Figure 3.7 (a) Project hierarchy (b) main.xml layout hierarchy

3. Make sure the activity code Layout Tabel.java is as below, see Figure 3.8

Activity LayoutTable.java

package contoh.layoutTabel;
import android.app.Activity;
import android.os.Bundle;
public class LayoutTabel extends Activity {
     /** Called when the activity is first created. */
     @Override
     public void onCreate(Bundle savedInstanceState) {
         super.onCreate(savedInstanceState);
         setContentView(R.layout.main);
     }
}


Figure 3.8. LayoutTable activity in the package

4. Run with the shortcut CTRL+F11 or right-click the package > run as > android Project.

5. See the results as in Figure 3.6.

Program Explanation 

Yes, I think it is easy to understand the layout of main.xml. Up to this point we are still playing around with xml. The layout of main.xml if seen from the Outline looks like figure 3.7 (b).

Some of the main.xml attributes that need to be considered include line 5, where android:stretchColumns means the column is set to fill the screen. Line 11 (android:padding) is an attribute to create distance between the content and the left and right edges of the textview.


Post a Comment

Previous Next

نموذج الاتصال