Saturday, June 21, 2014

Android Absolute Layout | Absolute Layout Example in Android | Create Layout using X,Y Coordinate in Android

Android Absolute layout:   Basically android have 5 types of layouts, we will discuss them one by one with examples-



Here I am Introducing to Absolute Layout:
Absolute Layout means that specify exact locations (x, y) coordinates of its children. This layout are not more in use because it is less flexible and harder to maintain than other types of layouts.

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

    <TextView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_x="10px"
        android:layout_y="10px"
        android:text="@string/app_name"
        android:textSize="22sp" />

    <ImageView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_x="10px"
        android:layout_y="110px"
        android:src="@drawable/desert" />

    <ImageView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_x="250px"
        android:layout_y="150px"
        android:src="@drawable/ic_launcher" />

    <TextView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_x="20px"
        android:layout_y="350px"
        android:text="androidhub4you.com"
        android:textSize="30sp" />

</AbsoluteLayout>

And use this MainActivity class to display your views-

package com.androidhub4you.absolutelayout;

import android.app.Activity;
import android.os.Bundle;

public class MainActivity extends Activity {

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

}


Your comments and feedback are awaited!
Thank You!




No comments:

Post a Comment