Introduction
This article explains TableLayout in Android. Android Studio is used to create the sample application.
TableLayout arranges its children into row and column. The Table Layout consists of a TableRow object to arrange children in a row.
In this, you will first use a TableLayout in your XML file and use Textviews according to your needs. I took five TextViews in this example. First, you will use one TextView inside the first Table Row, three TextViews inside a second Table Row and one TextView inside a third TableRow object.
Step 1
Create a project like this:
Step 2
In this, you will first use a TableLayout in your XML file and use Textviews according to your needs. I took five TextViews in this example. First, you will use one TextView inside the first Table Row, three TextViews inside a second Table Row and one TextView inside the third TableRow object.
Create an XML file and write this:
Step 3
Create a Java file and write this:
- package com.tablayoutexample;
- import android.os.Bundle;
- import android.app.Activity;
- import android.view.Menu;
-
- public class MainActivit extends Activity {
-
- @Override
- protected void onCreate(Bundle savedInstanceState) {
- super.onCreate(savedInstanceState);
- setContentView(R.layout.activity_main);
- }
-
- @Override
- public boolean onCreateOptionsMenu(Menu menu) {
-
- getMenuInflater().inflate(R.menu.main, menu);
- return true;
- }
-
- }
Step 4
Android Manifest.xml file
- <?xml version="1.0" encoding="utf-8"?>
- <manifest xmlns:android="http://schemas.android.com/apk/res/android"
- package="com.tablayoutexample"
- android:versionCode="1"
- android:versionName="1.0" >
-
- <uses-sdk
- android:minSdkVersion="7"
- android:targetSdkVersion="16" />
-
- <application
- android:allowBackup="true"
- android:icon="@drawable/ic_launcher"
- android:label="@string/app_name"
- android:theme="@style/AppTheme" >
- <activity
- android:name="com.tablayoutexample.MainActivit"
- android:label="@string/app_name" >
- <intent-filter>
- <action android:name="android.intent.action.MAIN" />
-
- <category android:name="android.intent.category.LAUNCHER" />
- </intent-filter>
- </activity>
- </application>
-
- </manifest>