/*******************************************************************************************
Program
Name:
Write an android application for relative layout, linear layout,
table layout and frame layout.
Author: sujith
Date:
12/9/2016
*******************************************************************************************/
Relative
Layout
AndroidManifest.xml
<?xml
version="1.0" encoding="utf-8"?>
<manifest
xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.sujithbaby.tri2">
<application
android:allowBackup="true"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:supportsRtl="true"
android:theme="@style/AppTheme">
<activity
android:name=".MainActivity">
<intent-filter>
<action
android:name="android.intent.action.MAIN" />
<category
android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
</manifest>
Activity_main.xml
<?xml
version="1.0" encoding="utf-8"?>
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/activity_main"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:padding="15dp"
tools:context="com.example.sujithbaby.tri2.MainActivity">
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="@string/example"
android:textSize="20dp"
android:textStyle="italic|bold"
/>
<RelativeLayout
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:gravity="center_vertical"
>
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="@string/user"
android:textSize="20dp"
android:textStyle="bold"
android:id="@+id/txt1"
/>
<EditText
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="@+id/txt1"
android:id="@+id/ed1"
/>
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:textSize="20dp"
android:text="@string/pass"
android:textStyle="bold"
android:layout_below="@+id/ed1"
android:id="@+id/txt2"
/>
<EditText
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="@+id/txt2"
android:id="@+id/ed2"
/>
<Button
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="@+id/ed2"
android:layout_centerHorizontal="true"
android:text="@string/login"/>
</RelativeLayout>
</RelativeLayout>
MainActivity.java
package
com.example.sujithbaby.tri2;
import
android.support.v7.app.AppCompatActivity;
import
android.os.Bundle;
public
class MainActivity extends AppCompatActivity {
@Override
protected
void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
}
}
Strings.xml
<resources>
<string
name="app_name">Relative Layout</string>
<string
name="user">Enter the User name</string>
<string
name="pass">Enter the Password</string>
<string
name="example">Login page using Relative layout
</string>
<string
name="login">Login </string>
</resources>
OUTPUT
Linear
layout
AndroidManifest.xml
<?xml
version="1.0" encoding="utf-8"?>
<manifest
xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.sujithbaby.tri3">
<application
android:allowBackup="true"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:supportsRtl="true"
android:theme="@style/AppTheme">
<activity
android:name=".MainActivity">
<intent-filter>
<action
android:name="android.intent.action.MAIN" />
<category
android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
</manifest>
Activity_main.xml
<?xml
version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/activity_main"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:padding="15dp">
<LinearLayout
android:layout_width="wrap_content"
android:layout_gravity="top"
android:layout_height="wrap_content">
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="@string/example"
android:textSize="20dp"
android:textStyle="italic|bold"
/>
</LinearLayout>
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="@string/user"
android:layout_marginTop="150dp"
android:textSize="20dp"
android:id="@+id/txt1"
/>
<EditText
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="@+id/ed1"
/>
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:textSize="20dp"
android:text="@string/pass"
android:id="@+id/txt2"
/>
<EditText
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="@+id/ed2"
/>
<Button
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:text="@string/login"/>
</LinearLayout>
MainActivity.java
package
com.example.sujithbaby.tri3;
import
android.support.v7.app.AppCompatActivity;
import
android.os.Bundle;
public
class MainActivity extends AppCompatActivity {
@Override
protected
void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
}
}
Strings.xml
<resources>
<string
name="app_name">Linear Layout</string>
<string
name="user">Enter the User name</string>
<string
name="pass">Enter the Password</string>
<string
name="example">Login page using Linear layout </string>
<string
name="login">Login </string>
</resources>
OUTPUT
Table
layout
AndroidManifest.xml
<?xml
version="1.0" encoding="utf-8"?>
<manifest
xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.sujithbaby.tr4">
<application
android:allowBackup="true"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:supportsRtl="true"
android:theme="@style/AppTheme">
<activity
android:name=".MainActivity">
<intent-filter>
<action
android:name="android.intent.action.MAIN" />
<category
android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
</manifest>
Activity_main.xml
<?xml
version="1.0" encoding="utf-8"?>
<TableLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/activity_main"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_margin="15dp"
>
<TableRow
android:padding="2dp"
>
<TextView
android:layout_width="match_parent"
android:layout_height="125dp"
android:textColor="#ffffff"
android:background="#39896E"
android:layout_weight="1"
android:gravity="center"
android:text="@string/r1"
/>
</TableRow>
<TableRow>
<TextView
android:layout_width="wrap_content"
android:layout_height="125dp"
android:layout_marginRight="2dp"
android:textColor="#ffffff"
android:background="#89381E"
android:gravity="center"
android:layout_weight="1"
android:text="@string/r2c1"
/>
<TextView
android:layout_width="wrap_content"
android:layout_height="125dp"
android:textColor="#ffffff"
android:gravity="center"
android:background="#891E65"
android:layout_weight="1"
android:text="@string/r2c2"
/>
</TableRow>
<TableRow
android:padding="2dp"
>
<TextView
android:layout_width="wrap_content"
android:gravity="center"
android:textColor="#ffffff"
android:layout_marginRight="2dp"
android:layout_height="125dp"
android:background="#1B4A0E"
android:layout_weight="1"
android:text="@string/r3c1"
/>
<TextView
android:layout_width="wrap_content"
android:gravity="center"
android:textColor="#ffffff"
android:layout_marginRight="2dp"
android:layout_height="125dp"
android:background="#12374A"
android:layout_weight="1"
android:text="@string/r3c2"
/>
<TextView
android:layout_width="wrap_content"
android:gravity="center"
android:textColor="#ffffff"
android:layout_height="125dp"
android:background="#47054A"
android:layout_weight="1"
android:text="@string/r3c3"
/>
</TableRow
>
</TableLayout>
MainActivity.java
package
com.example.sujithbaby.tr4;
import
android.support.v7.app.AppCompatActivity;
import
android.os.Bundle;
public
class MainActivity extends AppCompatActivity {
@Override
protected
void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
}
}
Strings.xml
<resources>
<string
name="app_name">Table Layout</string>
<string
name="r1">Row 1</string>
<string
name="r2c1">Row 2,Column 1</string>
<string
name="r2c2">Row 2,Column 2</string>
<string
name="r3c1">Row 3,Column 1</string>
<string
name="r3c2">Row 3,Column 2</string>
<string
name="r3c3">Row 3,Column 3</string>
</resources>
OUTPUT
Frame
Layout program
AndroidManifest.xml
<?xml
version="1.0" encoding="utf-8"?>
<manifest
xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.sujithbaby.tr5">
<application
android:allowBackup="true"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:supportsRtl="true"
android:theme="@style/AppTheme">
<activity
android:name=".MainActivity">
<intent-filter>
<action
android:name="android.intent.action.MAIN" />
<category
android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
</manifest>
Activity_main.xml
<?xml
version="1.0" encoding="utf-8"?>
<FrameLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/activity_main"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:padding="15dp">
<TextView
android:layout_width="350dp"
android:layout_height="280dp"
android:gravity="bottom"
android:background="#0C0854"
android:textSize="25dp"
android:textColor="#ffffff"
android:text="@string/i1"
/>
<TextView
android:layout_width="250dp"
android:layout_height="190dp"
android:textColor="#ffffff"
android:gravity="bottom"
android:background="#0F4D56"
android:textSize="25dp"
android:text="@string/i2"
/>
<TextView
android:layout_width="150dp"
android:layout_height="80dp"
android:textColor="#ffffff"
android:gravity="bottom"
android:textSize="25dp"
android:background="#EF0000"
android:text="@string/i3"
/>
</FrameLayout>
MainActivity.java
package
com.example.sujithbaby.tr5;
import
android.support.v7.app.AppCompatActivity;
import
android.os.Bundle;
public
class MainActivity extends AppCompatActivity {
@Override
protected
void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
}
}
Strings.xml
<resources>
<string
name="app_name">Grid Layout</string>
<string
name="i1">Item 1</string>
<string
name="i2">Item 2</string>
<string
name="i3">Item 3</string>
</resources>
OUTPUT
No comments:
Post a Comment