Ad Code

Responsive Advertisement

Basic Android Program 04

Question 04: Write a program to place Name, Age and mobile number centrally on the display screen using Absolute layout.

Download hole Program / Project code, by clicking following link:

What is CardView in Android Studio?
In Android programming, an Activity is a fundamental component of an Android application that represents a single screen with a user interface. It is an essential building block that defines the visual and interactive components of an application. An Activity is responsible for managing the user interface, handling user input, and coordinating with other components of the application.

CardView is a UI component in Android Studio that provides a flexible and customizable layout for displaying content in a card-like format. It is part of the Material Design guidelines for Android, which provide a set of design principles and guidelines for creating a consistent and intuitive user interface. CardView is essentially a container view that can hold other views such as text, images, or buttons, and provides a border and a drop shadow to make it stand out from the rest of the user interface. It is often used to display collections of content, such as images or articles, and allows users to interact with each item independently. Some of the key features of CardView include:
  • Customizable elevation: CardView provides a default elevation value that creates a subtle drop shadow effect, but developers can also customize the elevation value to create a more pronounced shadow effect.

  • Rounded corners: CardView has built-in support for rounded corners, which can be customized to match the design of the application.

  • Flexible sizing: CardView can be sized to match the content it contains, or it can be set to a fixed size to provide a consistent layout across different devices and screen sizes.
Overall, CardView is a powerful UI component that allows developers to create dynamic and engaging user interfaces in Android Studio. It provides a flexible layout that can be customized to match the design of the application, and it is supported by a wide range of devices and screen sizes.


Programming Code:

Following code write in: MainActivity.java
package com.go2collage.practical_04;

import androidx.appcompat.app.AppCompatActivity;

import android.os.Bundle;
import android.widget.TextView;

public class MainActivity extends AppCompatActivity {

// declaring variables
private TextView heading, para;

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

// initializing variables
heading = findViewById(R.id.txt1);
para = findViewById(R.id.txt2);

// set value to textView by using its ID
heading.setText("About us");
para.setText("go2collage is Technical Youtube Channel.");
}
}

Following code write in: 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="fill_parent"
android:layout_height="fill_parent"
tools:context=".MainActivity">

<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="go2collage"
android:layout_x="50dp"
android:layout_y="50dp"
android:textStyle="bold"
android:textSize="24sp"
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="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/txt1"
android:text=""
android:layout_x="50dp"
android:layout_y="120dp"
android:textSize="18sp"
android:textStyle="bold"
android:textColor="@color/black"
tools:ignore="HardcodedText" />

<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/txt2"
android:text=""
android:textSize="18sp"
android:textColor="@color/black"
android:layout_x="50dp"
android:layout_y="150dp"
tools:ignore="HardcodedText" />

</AbsoluteLayout>

Output:



Post a Comment

0 Comments

Ad Code

Responsive Advertisement