Question 03: Write a program to place Name, Age and mobile number linearly (Vertical) on the display screen using Linear layout.
Download hole Program / Project code, by clicking following link:
Name any three-layout manager in android studio?
Android Studio provides several layout managers that developers can use to create the user interface of their Android applications. Here are three commonly used layout managers:
- LinearLayout: LinearLayout arranges views in a linear manner, either horizontally or vertically. This is the simplest layout manager, and it is often used to create simple user interfaces with a single row or column of views.
- RelativeLayout: RelativeLayout arranges views relative to each other, using rules to position and align them. It is more flexible than LinearLayout and can be used to create more complex user interfaces.
- GridLayout: GridLayout arranges views in a grid of rows and columns. It allows developers to specify the number of rows and columns, as well as the size and spacing of each cell. This layout manager is often used to create table-like structures, such as calendars or grids of images.
Programming Code:
Following code write in: MainActivity.java
package com.go2collage.practical_03;
import androidx.appcompat.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);
}
}
Following code write in: activity_main.java
<?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"
android:layout_margin="20dp"
android:orientation="vertical">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="go2collage"
android:textAlignment="center"
android:layout_marginTop="20dp"
android:layout_gravity="center"
android:textStyle="bold"
android:textSize="24sp"
android:layout_marginBottom="30dp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
tools:ignore="HardcodedText" />
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Name: Pratik Deshmukh"
android:textSize="18sp"
android:textColor="@color/black"
tools:ignore="HardcodedText" />
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:textColor="@color/black"
android:text="Age: 20"
android:textSize="18sp"
tools:ignore="HardcodedText" />
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Mobile No.: 9080706050"
android:textSize="18sp"
android:textColor="@color/black"
android:layout_marginBottom="25dp"
tools:ignore="HardcodedText" />
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Name: Abdul Salam"
android:textSize="18sp"
android:textColor="@color/black"
tools:ignore="HardcodedText" />
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Age: 20"
android:textSize="18sp"
android:textColor="@color/black"
tools:ignore="HardcodedText" />
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Mobile No.: 4030201090"
android:textSize="18sp"
android:textColor="@color/black"
tools:ignore="HardcodedText" />
</LinearLayout>
Output:
0 Comments