Frame Layout Tutorial (Android UI)
Frame layouts are one of the simplest and most efficient types of layouts used by Android developers to organize views. They are used less often than some other layouts, simply because they are generally used to display only one view, or views which overlap. The frame layout is often used as a container layout, as it generally only has a single child view (often another layout, used to organize more than one view).
Views that we add to a FrameLayout are always anchored to the top left of the layout. To understand how FrameLayout works please consider the following XML layout-
<?xml version="1.0" encoding="utf-8"?>
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
>
<ImageView
android:src="@drawable/andro"
android:layout_height="wrap_content"
android:layout_width="wrap_content"
/>
</FrameLayout>
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
>
<ImageView
android:src="@drawable/andro"
android:layout_height="wrap_content"
android:layout_width="wrap_content"
/>
</FrameLayout>
Here is the output of above code-
In above example we create a FrameLayout and place ImageView inside it, ImageView displays an image (located in res/drawable folder). We can also add multiple views to a FrameLayout , but each will be stacked on top of the previous one.
|
|









Post a Comment