FrameLayout in android :

The FrameLayout is a placeholder on screen that you simply can use to show one view. Views that you add to a FrameLayout are always anchored to the top left of the layout. This example shows the way to use the FrameLayout to make a simple image viewer.

Note : This example (Project) is developed in Eclipse Version Kepler, tested on Android 4.4.2 (KitKat Version) and SDK build-tools 22.6.3

Solution Stuff :

In this Android FrameLayout example, you can use “android.widget.FrameLayout” class to render a FrameLayout with “android.widget.ImageView ” class to show image in android UI.

Complete Code :

1. Open “res/layout/activity_main.xml” file and add following XML code.

File : res/layout/activity_main.xml

Note that multiple image views are added to the FrameLayout, but every is stacked on top of the previous one. during this example, the second and third pictures are set to invisible. To create the second and third pictures visible one by one, use the following java code :

2. Open “MainAcitvity.class” file and add following JAVA code.

File : src/packagename/MainActivity.class

The preceding snippet programmatically locates the image views contained inside the FrameLayout and hides and shows the respective views. Figure  shows that the second image view is displayed when the user clicks the next Mobile button.

android frame layout example

Download Android Frame Layout example Source code :

Leave a Reply