Table of Contents
FrameLayout – Introduction
The layout in which an area is used to display a single child view is known as FrameLayout. FrameLayout is a suitable layout that can hold a single child’s view and allows you to control the position of the various children’s views to be displayed. You can handle the position of the child view by using this.
Create activity_frame_layout File in XML
<?xml version=”1.0″ encoding=”utf-8″?>
<LinearLayout
xmlns:android=”http://schemas.android.com/apk/res/android”
xmlns:app=”http://schemas.android.com/apk/res-auto”
xmlns:tools=”http://schemas.android.com/tools”
android:layout_width=”match_parent” // cover full screen
android:layout_height=”match_parent” // cover full screen
android:orientation=”vertical” // screen orientation will be vertical
android:layout_marginTop=”20dp” // It is used to give space from top screen
tools:context=”.frameLayout”>
<FrameLayout
android:layout_width=”match_parent”
android:layout_height=”wrap_content”> // cover the width of the text view, not full screen
<ImageView
android:layout_width=”match_parent”
android:layout_height=”150dp”
android:layout_gravity=”center_horizontal”
android:background=”#767676″/> // It is used to set the background color of our app
</FrameLayout>
<FrameLayout
android:layout_width=”match_parent”
android:layout_height=”wrap_content”
android:layout_marginTop=”30dp”>
<ImageView
android:layout_width=”match_parent”
android:layout_height=”150dp”
android:layout_gravity=”center_horizontal”
android:background=”#767676″/>
</FrameLayout>
<FrameLayout
android:layout_width=”match_parent”
android:layout_height=”wrap_content”
android:layout_marginTop=”30dp”>
<Button
android:layout_width=”match_parent”
android:layout_height=”wrap_content”
android:text=”Button”
android:textSize=”15sp” />
<Button
android:layout_width=”match_parent”
android:layout_height=”wrap_content”
android:text=”Button”
android:textSize=”15sp”
android:layout_marginTop=”50dp”/>
</FrameLayout>
<FrameLayout
android:layout_width=”match_parent”
android:layout_height=”wrap_content”
android:layout_marginTop=”30dp”>
<TextView
android:layout_width=”match_parent”
android:layout_height=”wrap_content”
android:text=”Hello, this is frame layout example”
android:gravity=”center”
android:textStyle=”bold” />
<EditText
android:layout_width=”match_parent”
android:layout_height=”wrap_content”
android:hint=”Type Something Here”
android:gravity=”center”
android:layout_marginTop=”20dp” />
</FrameLayout>
</LinearLayout>
Create frameLayout File in Java
package com.eiheducation.demo;
import androidx.appcompat.app.AppCompatActivity;
import android.os.Bundle;
public class frameLayout extends AppCompatActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_frame_layout);
}
}
Android Manifest File
<?xml version=”1.0″ encoding=”utf-8″?>
<manifest xmlns:android=”http://schemas.android.com/apk/res/android”
package=”com.eiheducation.demo”>
<application
android:allowBackup=”true”
android:icon=”@mipmap/ic_launcher”
android:label=”@string/app_name”
android:roundIcon=”@mipmap/ic_launcher_round”
android:supportsRtl=”true”
android:theme=”@style/Theme.EIHeducationDemo”>
<activity
android:name=”.MainActivity”
android:label=”@string/app_name”
android:theme=”@style/Theme.EIHeducationDemo.NoActionBar”>
<intent-filter>
<action android:name=”android.intent.action.MAIN” />
<category android:name=”android.intent.category.LAUNCHER” />
</intent-filter>
</activity>
<activity android:name=”.frameLayout”></activity>
</application>
</manifest>
FrameLayout – Output
Grammarly – Best Free Grammar checker | Spelling checker | Mistake-free document writer for Laptop/Desktop
Online Surveys – Earn Real Money by Online Surveys
Kids Books – 10+ books for Kids | Age group 2 – 10 | Improve knowledge & Productivity