How do 'android:foreground' and 'android:foregroundGravity' in FrameLayout affect its appearance?

SimplyProgrammer picture SimplyProgrammer · Jan 26, 2016 · Viewed 22.5k times · Source

FrameLayout has the attributes android:foreground, android:foregroundGravity and android:measureAllChildren. I have tried these attributes, but couldn't make out how they affect the layout's appearance or how they work.

<FrameLayout 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"
 android:foreground="@android:color/holo_blue_dark"
 android:foregroundGravity="center"
 android:measureAllChildren="true"
 android:paddingBottom="@dimen/activity_vertical_margin"
 android:paddingLeft="@dimen/activity_horizontal_margin"
 android:paddingRight="@dimen/activity_horizontal_margin"
 android:paddingTop="@dimen/activity_vertical_margin"
 tools:context="com.example.framelayoutdemo.MainActivity" >

<TextView
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:text="@string/hello_world" />

<ImageView
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:src="@android:drawable/btn_dialog" />

</FrameLayout>

I have googled, but couldn't find a help with these attributes. Please provide me a link which I can refer or help me with an example. Thanks

Answer

Mayur Kaul picture Mayur Kaul · Jan 26, 2016

android:foreground points to the foreground that your Framelayout needs to draw on top of all its children

android:foregroundGravity points to the gravity of that asset, if that asset is a drawable. That means if you are using

android:foreground="@android:drawable/bottom_bar"

Then your drawable is drawn on top of all its children and it is positioned in the center of the Framelayout

android:measureAllChildren : Determines whether to measure all children or just those in the VISIBLE or INVISIBLE state when measuring. Defaults to false. That means, if it is set to false, then all the elements in the GONE state are not taken into consideration when the Framelayout's measure phase is going around.

Hope that answers your question.