Skip to main content

SPAN in Android TableLayout

Finally after two days of hard work, I managed to solve the layout issue. Having to insert the AdMob ads in dictionary app, I need to do minor changes to the layout. This morning I realised that there should be a SPAN capability in the TableLayout (as similar to HTML table). I decided to give it a try and, Alhamdulillah it works.


SPAN in Android TableLayout

What is SPAN in table? It is a capability to merge several cells in a table. If it is a column span, than it is merging several columns in a row. In this example, I managed to merge 2 cells in a row (in line 21) and and 3 cells in a row (refer to line 85 in the code below).



Column span 2


Column span 3


And this is the XML code for the layout.

   1: <?xml version="1.0" encoding="utf-8"?>
   2: <TableLayout xmlns:android=""
   3:     android:orientation="vertical"
   4:     android:background="@drawable/bd"
   5:     android:layout_width="fill_parent"
   6:     android:layout_height="fill_parent"
   7:     android:stretchColumns="1"
   8:        >
   9:     <TableRow>
  10:         <TextView android:text="Perkataan Melayu" 
  11:             android:textColor="#ffffff"
  12:             android:layout_width="fill_parent" 
  13:             android:layout_height="wrap_content" />
  14:     </TableRow>
  15:     <TableRow>
  16:         <EditText android:text="" 
  17:             android:layout_column="0"
  18:             android:id="@+id/txtmelayu" 
  19:             android:layout_width="fill_parent" 
  20:             android:layout_height="wrap_content"
  21:             android:layout_span="2" />
  22:         <Button android:text="Cari" 
  23:             android:layout_column="2"
  24:             android:id="@+id/btncari" 
  25:             android:layout_width="wrap_content" 
  26:             android:layout_height="wrap_content" />
  27:     </TableRow>>
  28:     <TableRow>    
  29:             <TextView android:text="Bahasa Inggeris papar di sini" 
  30:             android:id="@+id/tveng" 
  31:             android:textColor="#ffffff"
  32:             android:layout_width="wrap_content" 
  33:             android:layout_height="wrap_content" />
  35:             <Button android:text="" 
  36:             android:layout_column="2" 
  37:             android:drawableLeft="@drawable/sound"
  38:             android:id="@+id/btnsebutan1" 
  39:             android:layout_width="wrap_content" 
  40:             android:layout_height="wrap_content" 
  41:             />
  42:     </TableRow>
  43:     <TableRow>
  44:         <TextView android:text="Bahasa Arab papar di sini" 
  45:             android:id="@+id/tvarab" 
  46:             android:textColor="#ffffff"
  47:             android:layout_width="wrap_content" 
  48:             android:layout_height="wrap_content" />
  49:             <Button android:text="" 
  50:             android:layout_column="2" 
  51:             android:drawableLeft="@drawable/sound"
  52:             android:id="@+id/btnsebutan" 
  53:             android:layout_width="wrap_content" 
  54:             android:layout_height="wrap_content" 
  55:             />
  56: </TableRow>
  57:     <LinearLayout android:gravity="center_horizontal">
  58:                 <Button android:text="Muat turun imej" 
  59:                android:id="@+id/btndownimej" 
  60:             android:layout_width="wrap_content" 
  61:             android:layout_height="wrap_content" 
  62:              />
  63:     </LinearLayout>
  64:     <TableRow android:gravity="center_horizontal">
  65:         <ImageView 
  66:         android:id="@+id/image1"
  67:         android:layout_width="100sp"
  68:         android:layout_height="100sp"
  69:         />
  70:     </TableRow>
  71:     <TableRow>
  72:         <TextView android:text=" " 
  73:             android:textColor="#ffffff"
  74:             android:layout_width="fill_parent" 
  75:             android:layout_height="wrap_content" />
  76:     </TableRow>
  77:     <TableRow android:gravity="center_horizontal">
  78:         <
  79:             xmlns:ads=""
  80:             android:id="@+id/adView1"
  81:             android:layout_width="wrap_content"
  82:             android:layout_height="wrap_content"
  83:             ads:adSize="BANNER"
  84:             ads:adUnitId="CHANGE_TO_YOUR_ADMOB_PUBLISHER_ID"
  85:             android:layout_span="3"
  86:             />
  87:     </TableRow>
  88: </TableLayout>


ScreenHunter_07 May. 19 09.43Autobot, ROLL-OUT!!!


Popular posts from this blog

Several English proverbs and the Malay pair

Or you could download here for the Malay proverbs app – English proverbs and the Malay pair Corpus Reference: Amir Muslim, 2009. Peribahasa dan ungkapan Inggeris-Melayu. DBP, Kuala Lumpur CTRL+F to search Proverbs in English Definition in English Similar Malay Proverbs Definition in Malay 1 Where there is a country, there are people. A country must have people. Ada air adalah ikan. Ada negeri adalah rakyatnya. 2 Dry bread at home is better than roast meat home's the best hujan emas di negeri orang,hujan batu di negeri sendiri Betapa baik pun tempat orang, baik lagi tempat sendiri. 3 There's no accounting for tastes We can't assume that every people have a same feel Kepala sama hitam hati lain-lain. Dalam kehidupan ini, setiap insan berbeza cara, kesukaan, perangai, tabia

Online database thru JSON in Android Studio

The tutorial is about how to connect Android apps and online database using the JSON formatted data interchange. The server facilities and JSON encoded data has been explained in the previous tutorials; ( Android and JSON Insert , Android and JSON Search ). The overview concept of JSON data inter change. JSON formatted data sample First we look at our database structure for this project. Part A: The online database The table is training, and this is the structure. There is a PHP script that generate a JSON encoded data from the above table. The PHP script to generate JSON formatted data; <?php //search.php /* * Following code will search training based on keywords */ // array for JSON response $response = array (); // include connect class require_once __DIR__ . '/connect.php' ; // connecting to db $db = new DB_CONNECT(); $keyword = $_GET [ "keyword" ]; // get idioms based on keyword //using LIKE $result =

Bootstrap Template for PHP database system - MyCompanyHR

HTML without framework is dull. Doing hard-coded CSS and JS are quite difficult with no promising result on cross platform compatibility. So I decided to explore BootStrap as they said it is the most popular web framework. What is BootStrap? - Bootstrap is the most popular HTML, CSS, and JavaScript framework for developing responsive, mobile-first web sites. (   ) Available here - Why you need Flat-UI? Seems like a beautiful theme to make my site look professional. Anyway you could get variety of BootStrap theme out there, feel free to select here Flat-UI is from DesignModo - Web Programming MyCompanyHR – PHP & MySQL mini project (with Boostrap HTML framework) Template 1: Template for the Lab Exercise. This is a project sample of a staff record management system. It has the PHP structured co

Login JSON Android using Login Activity

I’ve been trying to release this tutorial quite a while. At last after a long hard effort. Since HttpClient is not supported any more in Android SDK 23, I have to resort to org.json.JSONObject and library to do online database with JSON. The objective of this tutorial is to log-in from a mobile client with the username and password stored in an online database facility. STEP 1: Create a new Android project, this time choose the LoginActivity .

Contact Us at

Powered by EMF HTML Contact Form