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

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.


If measureallchildren is set to "true" then it will show actual width and height of the frame layout even if the views visibility is in gone state. For example

<?xml version="1.0" encoding="utf-8"?>
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
   android:id="@+id/myframe"
    android:orientation="vertical" android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:measureAllChildren="true"
    >
    <ImageView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:visibility="gone"
        android:src="@drawable/ic_launcher"/>

</FrameLayout>

Below is the code of MainActivity.java . if we use Toast to display height and width on screen.

public class MainActivity extends AppCompatActivity {
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.myframe_activity);
        FrameLayout frame=(FrameLayout)findViewById(R.id.frame);
        frame.measure(View.MeasureSpec.UNSPECIFIED, View.MeasureSpec.UNSPECIFIED);
        int width = frame.getMeasuredWidth();
        int height = frame.getMeasuredHeight();
        Toast.makeText(getApplicationContext(),"width="+width+"  height="+height,Toast.LENGTH_SHORT).show();

    }

}

if we run the App in the Emulator the output in the form of Toast message will be like this: width=72 height=72

Now if we change the value of measureAllChildren to false then Toast message output frame layout width and height will be: width=0 height=0