Practical No 5
Practical No 5
1. Write a program to place name, age and mobile number linearly(vertical) on the
display screen using linear layout.
Activity_main.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".MainActivity"
tools:ignore="ExtraText">
<Button
android:id="@+id/btn1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textSize="15sp"
android:text="Place:Thane" />
<Button
android:id="@+id/btn2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textSize="15sp"
android:text="Age:18" />
<Button
android:id="@+id/btn3"
android:layout_width="184dp"
android:layout_height="wrap_content"
android:text="Mob: 8855886741"
android:textSize="15sp" />
</LinearLayout>
MainActivity.Java
package com.example.tadvi;
import androidx.appcompat.app.AppCompatActivity;
import android.os.Bundle;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
}
}
2. Write a program to place name, age and mobile number Centrally on the display
screen using Absolute layout.
Activity_main.xml
<?xml version="1.0" encoding="utf-8"?>
<AbsoluteLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".MainActivity"
tools:ignore="ExtraText">
<Button
android:id="@+id/btn1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textSize="15sp"
android:layout_x="29dp"
android:layout_y="240dp"
android:text="Place Name:" />
<TextView
android:layout_width="139dp"
android:layout_height="wrap_content"
android:layout_x="211dp"
android:layout_y="249dp"
android:textSize="20sp"
android:textColor="@color/black"
android:text="Thane"/>
<Button
android:id="@+id/btn2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textSize="15sp"
android:layout_x="58dp"
android:layout_y="448dp"
android:text="Age:" />
<TextView
android:layout_width="139dp"
android:layout_height="wrap_content"
android:layout_x="216dp"
android:layout_y="461dp"
android:text="18"
android:textColor="@color/black"
android:textSize="20sp" />
<Button
android:id="@+id/btn3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Mobile No:"
android:layout_x="39dp"
android:layout_y="352dp"
android:textSize="15sp" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_x="212dp"
android:layout_y="363dp"
android:text="8855886741"
android:textColor="@color/black"
android:textSize="20sp" />
</AbsoluteLayout>
MainActivity.java
package com.example.tadvi;
import androidx.appcompat.app.AppCompatActivity;
import android.os.Bundle;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
}
}