Tuesday, May 12, 2015

Android program on Frame Layout

In frame layout we divide the screen in frames. In given example we take a picture and then write some data on that picture.So for that we take an image view and two text view to write some text on the image.
In activity_main.xml file we take a frame layout. then we take an image view and two text view on that image. One text view is on the top of the image and second text view is set in the center of the image.
Now no need to change in java file. Delete some data from java files that is unnecessary. In manifest file no any need to change the data.
For image on the screen take a pic in the drawable and give the path in the android:src field.

activity_main.xml
<?xml version="1.0" encoding="utf-8"?>
<FrameLayout
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    xmlns:android="http://schemas.android.com/apk/res/android">
    <ImageView
        android:src="@drawable/icon1"
        android:scaleType="fitCenter"
        android:layout_height="fill_parent"
        android:layout_width="fill_parent"/>
    <TextView
        android:text="This is Frame Layout!!!"
        android:textSize="24px"
        android:textColor="#cc0000"
        android:layout_height="fill_parent"
        android:layout_width="fill_parent"
        android:gravity="top"/>
    <TextView
        android:text="Android Development on Image"
        android:textSize="24px"
        android:textColor="#00dd00"
        android:layout_height="fill_parent"
        android:layout_width="fill_parent"
        android:gravity="center"/>
</FrameLayout>

MainActivity.java
package com.example.framelayout1;

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

public class MainActivity extends Activity {

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

@Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.main, menu);
return true;
}

}

manifest.xml
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="com.example.framelayout1"
    android:versionCode="1"
    android:versionName="1.0" >

    <uses-sdk
        android:minSdkVersion="8"
        android:targetSdkVersion="18" />

    <application
        android:allowBackup="true"
        android:icon="@drawable/ic_launcher"
        android:label="@string/app_name"
        android:theme="@style/AppTheme" >
        <activity
            android:name="com.example.framelayout1.MainActivity"
            android:label="@string/app_name" >
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />

                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>
    </application>

</manifest>

No comments:

Post a Comment