WEB DEVELOPER SITE
HTMLCSSJAVASCRIPTSQLPHPBOOTSTRAPJQUERYANGULARXML
 

Android Absolute Layout


Absolute Layout is a layout used to design the custom layouts.


Android Absolute Layout Syntax

Below the Syntax of Absolute Layout:

< AbsoluteLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="fill_parent" android:layout_height="fill_parent" >
<!-- add child view’s here -->
</AbsoluteLayout>

AbsoluteLayout Android

ID:android id is a attribute used to unique identify a Absolute Layout.

Example

below the example follow as :
<AbsoluteLayout
android:id="@+id/absoluteLayout"
android:layout_width="fill_parent"
android:layout_height="fill_parent"/>

layout_x Absolute Layout layout_x attribute is used to specify the x- coordinate of TextView or any other view .

Example

below the example follow as :
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="welookups"
android:textSize="27sp"
android:layout_x="220px" /> 

layout_y AbsoluteLayout layout_y attribute is used to specify the y- coordinate of the TextView or any other view

Example

below the example follow as :we set the 250px value for the y- coordinate.
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="welookups"
android:textSize="28sp"
android:layout_y="280px"/>





Example of Android Absolute Layout

Create a new project and name MyapplicationTest Select File -> New -> New Project. Fill the forms and click “Finish” button.
Open res -> layout -> activity_main.xml (or) main.xml

  <AbsoluteLayout xmlns:android="http://schemas.android.com/apk/res/android"
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"
        android:background="#afc">

  <TextView
            android:layout_x="120px"
            android:layout_y="120px"
            android:text="User Name"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content" />
    <EditText
            android:layout_x="260px"
            android:layout_y="90px"
            android:width="110px"
            android:layout_width="200dp"
            android:layout_height="wrap_content" />
    <TextView
            android:layout_x="120px"
            android:layout_y="220px"
            android:text="Password"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content" />
     <EditText
            android:layout_x="250px"
            android:layout_y="150px"
            android:width="100px"
            android:layout_width="200dp"
            android:layout_height="wrap_content" />
  <Button
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="Log In"
            android:layout_x="300px"
            android:layout_y="300px"/>
</AbsoluteLayout>

Now Open java -> package -> MainActivity.java and paste the below code.

package com.faceadityasingh.com.myapplicationtest;

import android.support.v7.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);
    }

    @Override
    public boolean onCreateOptionsMenu(Menu menu) {
        // Inflate the menu; this adds items to the action bar if it is present.
        getMenuInflater().inflate(R.menu.menu_main, menu);
        return true;
    }

    @Override
    public boolean onOptionsItemSelected(MenuItem item) {
        // Handle action bar item clicks here. The action bar will
        // automatically handle clicks on the Home/Up button, so long
        // as you specify a parent activity in AndroidManifest.xml.
        int id = item.getItemId();

        //noinspection SimplifiableIfStatement
        if (id == R.id.action_settings) {
            return true;
        }

        return super.onOptionsItemSelected(item);
    }
}

Now Open Manifests and click on AndroidManifest.xml and paste the below code


<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="example.abhiandriod.absolytelayoutexample" >

 <application
        android:allowBackup="true"
        android:icon="@mipmap/ic_launcher"
        android:label="@string/app_name"
        android:theme="@style/AppTheme" >
     <activity
            android:name=".MainActivity"
            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>

Open res -> values ->strings.xml and paste the below code.

<resources>
    AbsolyteLayoutExample
    Hello world!
    Settings
</resources>