Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
0% found this document useful (0 votes)
47 views

Android Frame Layout

Frame Layout is designed to hold a single child view but can contain multiple views if their positions are controlled with gravity attributes. It demonstrates creating an Android app with a FrameLayout containing an ImageView and TextView centered on the screen.

Uploaded by

Mayur Mahajan
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
47 views

Android Frame Layout

Frame Layout is designed to hold a single child view but can contain multiple views if their positions are controlled with gravity attributes. It demonstrates creating an Android app with a FrameLayout containing an ImageView and TextView centered on the screen.

Uploaded by

Mayur Mahajan
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 4

Android Frame Layout

Frame Layout 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.

Frame Layout

FrameLayout Attributes
Following are the important attributes specific to FrameLayout −

Example
This example will take you through simple steps to show how to create your own
Android application using frame layout. Follow the following steps to modify the
Android application we created in Hello World Example chapter −

Following is the content of the modified main activity file


src/com.example.demo/MainActivity.java. This file can include each of the
fundamental lifecycle methods.

package com.example.demo;

import android.os.Bundle;
import android.app.Activity;

public class MainActivity extends Activity {


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

Following will be the content of res/layout/activity_main.xml file −

<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>

Following will be the content of res/values/strings.xml to define two new


constants −

<?xml version="1.0" encoding="utf-8"?>


<resources>
<string name="app_name">demo</string>
<string name="action_settings">Settings</string>
</resources>

Let's try to run our modified Hello World! application we just modified. I assume
you had created your AVD while doing environment setup. To run the app from
Android Studio, open one of your project's activity files and click Run

icon from the toolbar. Android Studio installs the app on your AVD and starts it and if
everything is fine with your setup and application, it will display following Emulator
window −

You might also like