Android FrameLayout Example Tutorial

How to use FrameLayout in android.

FrameLayout is used to create overlapped screens on android apps like replacing widgets, images, buttons, textView without erasing or hiding them. This works same as display backgrounds and use anything to make backgrounds there are no limitations on it. So here is the complete step by step tutorial for Android FrameLayout Example Tutorial.

android-project-download-code-button

What i am doing in this project: I am creating a frame layout using activity_main.xml layout file and on it first define single imageView tag and above it setting up two different textView tags like overlapping imageview. You cannot do this type of typical replacing in any other android layout.

Android FrameLayout Example Tutorial.

Code for MainActivity.java file.

package com.android_examples.com.framelayoutandroid;
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);
 }
}

Code for activity_main.xml layout file.

 <FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
 xmlns:tools="http://schemas.android.com/tools"
 android:layout_width="fill_parent"
 android:layout_height="fill_parent"
 android:layout_gravity="center_vertical"
 tools:context="com.android_examples.com.framelayoutandroid.MainActivity" >

 <ImageView 
 android:id="@+id/ImgView"
 android:layout_height="fill_parent"
 android:layout_width="fill_parent"
 android:src="@drawable/background"/>

 <TextView
 android:id="@+id/textView1"
 android:layout_width="wrap_content"
 android:layout_height="wrap_content"
 android:text="Hello, Android Developers"
 android:textAppearance="?android:attr/textAppearanceLarge"
 android:layout_marginTop="50dp"
 android:layout_marginLeft="30dp"
 android:background="@color/material_grey_100" />

 <TextView
 android:id="@+id/textView2"
 android:layout_width="wrap_content"
 android:layout_height="wrap_content"
 android:text="Android-Examples.com"
 android:layout_marginTop="350dp"
 android:layout_marginLeft="50dp"
 android:textAppearance="?android:attr/textAppearanceLarge"
 android:background="@color/material_grey_100" />
 
</FrameLayout>

Screenshot:

Android FrameLayout Example Tutorial

Click Here To Download Android FrameLayout Example Tutorial project.

Leave a Reply

Your email address will not be published. Required fields are marked *