TableLayout in Android Studio With App | How To Create

TableLayout in Android

TableLayout in Android – In TableLayout, the views are arranged in rows and columns. For this, you need to use the TableRow elements and define the views that you want to be displayed in a row of the table. You can arrange each view as a cell of the row so that a row would contain multiple

Create activity_table_layout file in XML

<?xml version=”1.0″ encoding=”utf-8″?>

<TableLayout
xmlns:android=”http://schemas.android.com/apk/res/android”
xmlns:app=”http://schemas.android.com/apk/res-auto”
xmlns:tools=”http://schemas.android.com/tools”
android:layout_width=”match_parent” // cover full screen
android:layout_height=”match_parent” // cover full screen
android:gravity=”center” // screen orientation will be vertical
tools:context=”.tableLayout”>

<TableRow
android:gravity=”center” // screen orientation will be vertical
android:layout_width=”wrap_content”
android:layout_height=”wrap_content”>

<Button
android:layout_width=”wrap_content” // cover the width of the text view, not full screen
android:layout_height=”wrap_content” // cover the width of the text view, not full screen
android:text=”Row 1″
android:layout_marginRight=”15dp”/> // It is used to give space from right screen

<Button
android:layout_width=”wrap_content”
android:layout_height=”wrap_content”
android:text=”Row 2″ />

</TableRow>

<TableRow
android:gravity=”left”
android:layout_width=”wrap_content”
android:layout_height=”wrap_content”
android:layout_marginLeft=”15dp” // It is used to give space from left screen
android:layout_marginTop=”15dp”>

<Button
android:layout_width=”wrap_content”
android:layout_height=”wrap_content”
android:text=”Row 3″
android:layout_marginRight=”15dp” />

<Button
android:layout_width=”wrap_content”
android:layout_height=”wrap_content”
android:text=”Row 4″/>

</TableRow>

<TableRow
android:gravity=”right”
android:layout_width=”wrap_content”
android:layout_height=”wrap_content”
android:layout_marginRight=”15dp”
android:layout_marginTop=”15dp”>

<Button
android:layout_width=”wrap_content”
android:layout_height=”wrap_content”
android:text=”Row 5″
android:layout_marginRight=”15dp” />

<Button
android:layout_width=”wrap_content”
android:layout_height=”wrap_content”
android:text=”Row 6″/>

</TableRow>

<TableRow
android:gravity=”center”
android:layout_width=”wrap_content”
android:layout_height=”wrap_content”
android:layout_marginTop=”15dp”>

<Button
android:layout_width=”wrap_content”
android:layout_height=”wrap_content”
android:text=”Row 7″
android:layout_marginRight=”15dp”/>

<Button
android:layout_width=”wrap_content”
android:layout_height=”wrap_content”
android:text=”Row 8″ />

</TableRow>

<TableRow
android:gravity=”center”
android:layout_width=”wrap_content”
android:layout_height=”wrap_content”
android:layout_marginTop=”15dp”>

<Button
android:layout_width=”wrap_content”
android:layout_height=”wrap_content”
android:text=”Row 9″
android:layout_marginRight=”15dp”/>

<Button
android:layout_width=”wrap_content”
android:layout_height=”wrap_content”
android:text=”Row 10″ />

</TableRow>

</TableLayout>

Create tableLayout File in Java

package com.eiheducation.demo;

import androidx.appcompat.app.AppCompatActivity;

import android.os.Bundle;

public class tableLayout extends AppCompatActivity {

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_table_layout);
}
}

Android Manifest File

<?xml version=”1.0″ encoding=”utf-8″?>
<manifest xmlns:android=”http://schemas.android.com/apk/res/android”
package=”com.eiheducation.demo”>

<application
android:allowBackup=”true”
android:icon=”@mipmap/ic_launcher”
android:label=”@string/app_name”
android:roundIcon=”@mipmap/ic_launcher_round”
android:supportsRtl=”true”
android:theme=”@style/Theme.EIHeducationDemo”>
<activity
android:name=”.MainActivity”
android:label=”@string/app_name”
android:theme=”@style/Theme.EIHeducationDemo.NoActionBar”>
<intent-filter>
<action android:name=”android.intent.action.MAIN” />

<category android:name=”android.intent.category.LAUNCHER” />
</intent-filter>
</activity>
<activity android:name=”.tableLayout”></activity>
</application>

</manifest>

TableLayout in Android – Output

TableLayout in Android Studio With App | How To Create

Check Out the Headphones – 50% to 70% Off
Check Out the Earbuds – 50% to 70% Off
Grammarly – Best Free Grammar checker | Spelling checker | Mistake-free document writer for Laptop/Desktop
Check Out The LAB Configuration eBook – Class A, Class B, Class C, MiN worth $78 Get at $18

Leave a Reply

Your email address will not be published.