Tuesday, June 10, 2014

Android FrameLayout demo | Framelayout Example in Android | Create Frame Layout in android

Android Frame layout:   Basically android have 5 types of layouts, we will discuss them one by one with examples-



Frame Layout means each view comes in form of frame like a view upon another view. This layout helps us if we want to display any text or image on any background image.

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    tools:context=".MainActivity" >

    <TextView
        android:id="@+id/text1"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:textSize="25sp"
        android:layout_marginTop="5dp"
        android:layout_centerHorizontal="true"
        android:text="@string/hello_world" />

    <FrameLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_below="@+id/text1"
        android:layout_marginTop="15dp" >

        <ImageView
            android:layout_width="match_parent"
            android:layout_height="300dp"
            android:scaleType="fitXY"
            android:layout_gravity="center"
            android:src="@drawable/desert" />
       
        <ImageView
            android:layout_width="100dp"
            android:layout_height="100dp"
            android:layout_gravity="center"
            android:src="@drawable/ic_launcher" />

        <TextView
            android:id="@+id/text2"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_gravity="center"
            android:textColor="#CCCC00"
            android:textSize="35sp"
            android:text="@string/app_name" />
    </FrameLayout>

</RelativeLayout>

And use this MainActivity class to display your views-

package com.androidhub4you.framelayout;

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

public class MainActivity extends Activity {

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


}



Your comments and feedback are awaited!
Thank You!




1 comment :

  1. Can you please provide a solution for this:
    http://stackoverflow.com/questions/24256488/android-background-url-inside-cdata

    ReplyDelete

Note: Only a member of this blog may post a comment.