3 Program to place Name, Age and Mobile number centrally on the display screen using Absolute Layout in Android Studio.

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

<manifest xmlns:android="http://schemas.android.com/apk/res/android"

    package="com.blogspot.codingatharva.firstapp" >

    <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/AppTheme" >

        <activity android:name=".MainActivity" >

            <intent-filter>

                <action android:name="android.intent.action.MAIN" />


                <category android:name="android.intent.category.LAUNCHER" />

            </intent-filter>

        </activity>

    </application>



</manifest>


activity_main.xml:
<?xml version="1.0" encoding="utf-8"?>
<AbsoluteLayout 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"
    android:layout_height="match_parent"
    android:paddingLeft="16dp"
    android:paddingTop="16dp"
    android:paddingRight="16dp"
    tools:context=".MainActivity">


    <TextView
        android:id="@+id/student_name"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_x="125dp"
        android:layout_y="280dp"
        android:text="Name:"
        android:textColor="#86AD33"
        android:textSize="20dp"
        android:textStyle="bold" />

    <TextView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_x="125dp"
        android:layout_y="304dp"
        android:text="Age:"
        android:textColor="#86AD33"
        android:textSize="20dp"
        android:textStyle="bold" />

    <TextView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_x="125dp"
        android:layout_y="328dp"
        android:text="Mobile Number:"
        android:textColor="#86AD33"
        android:textSize="20dp"
        android:textStyle="bold" />


</AbsoluteLayout>


MainActivity.java:
package com.blogspot.codingatharva.firstapp;

import androidx.appcompat.app.AppCompatActivity;

import android.os.Bundle;

public class MainActivity extends AppCompatActivity {

    @Override

    protected void onCreate(Bundle savedInstanceState) {

        super.onCreate(savedInstanceState);

        setContentView(R.layout.activity_main);

    }

}

Output:

 centrally on the display screen using  Absolute Layout in Android Studio

Previous
Next Post »