Saturday 21 January 2017

Android Frame Layout

A Frame means an area which can hold view like an photoframe which can hold a photo and can arrange other photos as a stack in frame means on top of each other.

FrameLayout is designed to block out an area on the screen to display a single item. Generally, FrameLayout should be used to hold a single child view, because it can be difficult to organize child views in a way that's scalable to different screen sizes without the children overlapping each other. You can, however, add multiple children to a FrameLayout and control their position within the FrameLayout by assigning gravity to each child, using the android:layout_gravity attribute.
Child views are drawn in a stack, with the most recently added child on top. The size of the FrameLayout is the size of its largest child (plus padding), visible or not (if the FrameLayout's parent permits). Views that are GONE are used for sizing only if setConsiderGoneChildrenWhenMeasuring() is set to true.
Here is the the image that shows an layout of an android frame layout -

Android FrameLayout Attributes are as below -

Attribute & Description
1
android:id
This is the ID which uniquely identifies the layout.
2
android:foreground
This defines the drawable to draw over the content and possible values may be a color value, in the form of "#rgb", "#argb", "#rrggbb", or "#aarrggbb".
3
android:foregroundGravity
Defines the gravity to apply to the foreground drawable. The gravity defaults to fill. Possible values are top, bottom, left, right, center, center_vertical, center_horizontal etc.
4
android:measureAllChildren
Determines whether to measure all children or just those in the VISIBLE or INVISIBLE state when measuring. Defaults to false.
Below is an simple example of Android Frame Layout -

<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
   android:layout_width="fill_parent"
   android:layout_height="fill_parent">
   
   <ImageView 
      android:src="@drawable/ic_launcher"
      android:scaleType="fitCenter"
      android:layout_height="250px"
      android:layout_width="250px"/>
   
   <TextView
      android:text="Frame Demo"
      android:textSize="30px"
      android:textStyle="bold"
      android:layout_height="fill_parent"
      android:layout_width="fill_parent"
      android:gravity="center"/>
</FrameLayout>

Here is an output of this screen -

Android Frame Layout is mostly used with Navigation Drawer to show the main content of navigation drawer controls after click.It will be discussed in upcoming blogs.


No comments:

Post a Comment