WEB DEVELOPER SITE
HTMLCSSJAVASCRIPTSQLPHPBOOTSTRAPJQUERYANGULARXML
 

Android Frame Layout


Frame Layout Frame Layout is the layout to organize view controls.This can change UI to control block an area on the screen.


Android Frame Layout

we can add various child to a FrameLayout.

Attributes are Frame Layout

  • android:id This is called unique identifies the layout R.java file

    Example of android:id

    <FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/frameLayout"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"/>
    

    android:foreground we can change draw over the content and this may be a color value. such as color we can add various child to a foreground.

    Example android:foreground

    
      <FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
    
            android:id="@+id/framelayout"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:layout_gravity="center"
            android:foreground="#f0a000"
            android:foregroundGravity="fill"
            tools:layout_editor_absoluteX="19dp"
            tools:layout_editor_absoluteY="225dp">
    
            <LinearLayout
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_centerInParent="true"
                android:orientation="vertical">
    
                <!-- Imageview will not be shown because of foreground color which is drawn over it-->
    
                <ImageView
                    android:layout_width="250dp"
                    android:layout_height="250dp"
                    android:layout_marginBottom="10dp"
                    android:scaleType="centerCrop"
                    android:src="@mipmap/ic_launcher" />
    
              <!--Textview will not be shown because of foreground color is drawn over it-->
    
                <TextView
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:gravity="center_horizontal"
                    android:text="Welookups" />
    
      </LinearLayout>
    
      </FrameLayout>
    
    
  • android:foregroundGravity: Main use to change value of values in the form of “top”, ”center_vertical” , ”fill_vertical”, ”center_horizontal”, ”fill_horizontal”, ”center”, ”fill”, ”clip_vertical”, ”clip_horizontal”, ”bottom”, ”left” or ”right”
  • android:measureAllChildren: This is is measure of childern view or invisible it work on Boolean condition true or false .

    When your application measureallchildren is set true it will show visible width and height of frame layout

  • measureAllChildren attribute:

    
        <?xml version="1.0" encoding="utf-8"?>
      <FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
            android:id="@+id/frame"
            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"
                  />
    
       </FrameLayout>
    
    
Below is the code of MainActivity.java

public class MainActivity extends Activity {
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.demo);
        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();

    }

}

android:visibility

  • visible This view is visible
  • invisible This view is not visible but present
  • gone neither present nor visible


Add Example of Android Frame Layout

we can create project

Select File -> New -> New Project in Android Studio then clicked finished.

Now open res -> layout -> activity_main.xml and add this code

    tools:context=".MainActivity">
   <FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
        android:id="@+id/frameLayout"
        android:layout_width="fill_parent"
        android:layout_height="fill_parent">
        <ImageView
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:scaleType="setXY"
            android:src="@drawable/oreo-lg" />
        <extView
            android:layout_width="fill_parent"
            android:layout_height="fill_parent"
            android:gravity="center"
            android:text="WELOOKUPS"
            android:textSize="32sp"
            android:textColor="#fa0"
            android:textStyle="bold" />
    </FrameLayout>

at last add MainActivity.java has default java code or add the below code


package abhiandroid.com.framewithoutgravity;

import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;

public class MainActivity extends AppCompatActivity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
    }
}