MainActivity.java:

package com.example.appone;

import android.os.Bundle;
import android.widget.Button;
import android.widget.TextView;

import androidx.appcompat.app.AppCompatActivity;

public class MainActivity extends AppCompatActivity {

    Button btnLinear, btnTable, btnGrid,
            btnFrame, btnConstraint;

    TextView txtResult;

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


        btnLinear = findViewById(R.id.btnLinear);
        btnTable = findViewById(R.id.btnTable);
        btnGrid = findViewById(R.id.btnGrid);
        btnFrame = findViewById(R.id.btnFrame);
        btnConstraint = findViewById(R.id.btnConstraint);

        txtResult = findViewById(R.id.txtResult);


        // Linear Layout

        btnLinear.setOnClickListener(v ->

                txtResult.setText(
                        "LINEAR LAYOUT\n\n" +
                                "[ Login ]\n" +
                                "[ Register ]\n\n" +
                                "Views are arranged\n" +

                                "one below another."
                ));


        // Table Layout

        btnTable.setOnClickListener(v ->

                txtResult.setText(
                        "TABLE LAYOUT\n\n" +
                                "Name : Name\n" +
                                "Email : name@gmail.com\n\n" +
                                "Views are arranged\n" +
                                "in rows and columns."
                ));


        // Grid Layout

        btnGrid.setOnClickListener(v ->

                txtResult.setText(
                        "GRID LAYOUT\n\n" +
                                "[1]   [2]\n" +
                                "[3]   [4]\n\n" +
                                "Views are arranged\n" +
                                "like a grid."
                ));


        // Frame Layout

        btnFrame.setOnClickListener(v ->

                txtResult.setText(
                        "FRAME LAYOUT\n\n" +
                                "Only one view is generally\n" +
                                "visible at a time.\n\n" +
                                "Views can overlap."
                ));


        // Constraint Layout

        btnConstraint.setOnClickListener(v ->



                txtResult.setText(
                        "CONSTRAINT LAYOUT\n\n" +
                                "[ Submit ]\n\n" +
                                "Views are positioned\n" +
                                "using constraints."
                ));

    }
}


activity_main.xml:

<?xml version="1.0" encoding="utf-8"?>

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical"
    android:padding="16dp">

    <!-- Title -->

    <TextView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="DIFFERENT ANDROID LAYOUTS"
        android:textSize="24sp"
        android:textStyle="bold"
        android:layout_gravity="center"
        android:layout_marginTop="50dp" />

    <!-- First Row -->

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:gravity="center"
        android:orientation="horizontal"
        android:layout_marginTop="20dp">

        <Button
            android:id="@+id/btnLinear"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="Linear" />


        <Button
            android:id="@+id/btnTable"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="Table"
            android:layout_marginStart="10dp" />

        <Button
            android:id="@+id/btnGrid"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="Grid"
            android:layout_marginStart="10dp" />

    </LinearLayout>


    <!-- Second Row -->

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:gravity="center"
        android:orientation="horizontal"
        android:layout_marginTop="10dp">

        <Button
            android:id="@+id/btnFrame"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="Frame" />

        <Button
            android:id="@+id/btnConstraint"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="Constraint"
            android:layout_marginStart="10dp" />

    </LinearLayout>


    <!-- Display Area -->

    <TextView
        android:id="@+id/txtResult"


        android:layout_width="match_parent"
        android:layout_height="0dp"
        android:layout_weight="1"
        android:gravity="center"
        android:text="Click any button to view the layout."
        android:textSize="22sp"
        android:padding="25dp" />

</LinearLayout>
