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!




Tuesday, June 10, 2014

Android FrameLayout demo | Framelayout Example in Android | Create Frame Layout in android

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



Frame Layout means each view comes in form of frame like a view upon another view. This layout helps us if we want to display any text or image on any background image.

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    tools:context=".MainActivity" >

    <TextView
        android:id="@+id/text1"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:textSize="25sp"
        android:layout_marginTop="5dp"
        android:layout_centerHorizontal="true"
        android:text="@string/hello_world" />

    <FrameLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_below="@+id/text1"
        android:layout_marginTop="15dp" >

        <ImageView
            android:layout_width="match_parent"
            android:layout_height="300dp"
            android:scaleType="fitXY"
            android:layout_gravity="center"
            android:src="@drawable/desert" />
       
        <ImageView
            android:layout_width="100dp"
            android:layout_height="100dp"
            android:layout_gravity="center"
            android:src="@drawable/ic_launcher" />

        <TextView
            android:id="@+id/text2"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_gravity="center"
            android:textColor="#CCCC00"
            android:textSize="35sp"
            android:text="@string/app_name" />
    </FrameLayout>

</RelativeLayout>

And use this MainActivity class to display your views-

package com.androidhub4you.framelayout;

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!