0% found this document useful (0 votes)
12 views6 pages

AAD Week4 LDQ

Uploaded by

Naveen S
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
12 views6 pages

AAD Week4 LDQ

Uploaded by

Naveen S
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 6

Android Application Development

Week 4 - Long Descriptive Question and Answer

1. Create different View in Android Application with example

In Android, there are various types of views that can be used to create different
user interface elements in an application. Here are a few examples of different
views in Android:

1. TextView: This view is used to display text on the screen. It can be used for
labels, headings, or any other text-based content.
Example:

<TextView

android:id="@+id/my_text_view"

android:layout_width=“match_parent”

android:layout_height=“wrap_content"

android:text="Hello, World!” />

Inside java or kotlin class files (i.e..for eg.MainActivity.java ) we need to instan-


tiate the view to use textview.

TextView tv = (TextView) findViewById(R.id.my_text_view);

2. EditText: This view is used to allow users to enter text input. It can be used
for login screens, search bars, or any other user input field.

Example:

<EditText

android:id=“@+id/my_edit_text"

android:layout_width=“match_parent"

android:layout_height="wrap_content"

android:hint="Enter your name”/>

Inside java or kotlin class files (i.e..for eg.MainActivity.java ) we need to instan-


tiate the view to use edittext.

EditText et = (EditText) findViewById(R.id.my_edit_text);


3. Button: This view is used to create clickable buttons that perform actions or
trigger events. It can be used for submitting forms, navigating to other
screens, or any other user interaction.

Example:

<Button

android:id=“@+id/my_button"

android:layout_width=“match_parent”

android:layout_height=“wrap_content"

android:text="Click me” />

Inside java or kotlin class files (i.e..for eg.MainActivity.java ) we need to instan-


tiate the view to use button.

Button btn = (Button) findViewById(R.id.my_button);

4. ImageView: This view is used to display images on the screen. It can be


used for logos, icons, or any other visual content.

Example:

<ImageView

android:id=“@+id/my_image_view"

android:layout_width=“match_parent"

android:layout_height=“wrap_content”

android:scale_type=“CenterCrop”

android:src=“@drawable/my_image" />

Inside java or kotlin class files (i.e..for eg.MainActivity.java ) we need to instan-


tiate the view to use button.

ImageView iv = (ImageView) findViewById(R.id.my_image_view);


5. ProgressBar: This view is used to display a progress bar that shows the
progress of an ongoing task or operation. It can be used for file uploads,
downloads, or any other long-running process.

Example:

<ProgressBar

android:id=“@+id/my_progress_bar”

android:layout_width=“wrap_content"

android:layout_height="wrap_content" />

These are some few examples of the different types of views that can be used in
an Android application. By combining these views and using various layout tech-
niques, developers can create a wide range of different user interfaces and user
experiences in their applications.

A real time example of the above said views is given below.

activity_dummy_layout.xml

<?xml version="1.0" encoding="utf-8"?>

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:padding="@dimen/padding"
android:orientation="vertical">

<TextView
android:id="@+id/my_text_view"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="@dimen/padding"
android:textSize="@dimen/txtSize"
android:text="Hello, World!" />

<EditText
android:id="@+id/my_edit_text"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="@dimen/padding"
android:textSize="@dimen/txtSize"
android:hint="Enter your name" />

<Button
android:id="@+id/my_button"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="@dimen/padding"
android:textSize="@dimen/txtSize"
android:textColorHint="#ffffff"
android:hint="Click Me" />

<ImageView
android:id="@+id/my_image_view"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_margin="@dimen/padding"
android:scaleType="centerCrop"
android:background="@drawable/ic_launcher_background"
android:src="@drawable/ic_launcher_foreground" />

<ProgressBar
android:id="@+id/
m y_progress_bar"
android:layout_mar-
gin="@dimen/padding"
android:layout_width="wrap_con-
tent"
android:layout_height="wrap_con-
tent" />
</LinearLayout>

Output:

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy