0% found this document useful (0 votes)
7 views8 pages

Mada Unit-1

The document provides a step-by-step guide for creating an Android activity, including project setup, activity creation, layout definition, and code writing. It also explains key concepts related to Views in Android, including various types of Views and their functionalities. Additionally, it outlines different layout types available in the Android SDK, emphasizing the use of Constraint Layout for complex interfaces.

Uploaded by

MARAMMA THALLI
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)
7 views8 pages

Mada Unit-1

The document provides a step-by-step guide for creating an Android activity, including project setup, activity creation, layout definition, and code writing. It also explains key concepts related to Views in Android, including various types of Views and their functionalities. Additionally, it outlines different layout types available in the Android SDK, emphasizing the use of Constraint Layout for complex interfaces.

Uploaded by

MARAMMA THALLI
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/ 8

CREATING ANDROID ACTIVITY

Step 1: Create a new Android project

- Open Android Studio and create a new project.

- Choose "Empty Activity" as the project template.

Step 2: Create a new Activity

- In the project navigator, right-click on the package name (e.g., "com.example.myapp").

- Select "New" > "Activity" > "Empty Activity".

- Name the Activity (e.g., "MyActivity").

Step 3: Define the Activity layout

- Create a new layout file (e.g., "activity_my.xml") in the "res/layout" directory.

- Define the user interface elements (e.g., buttons, text views) using XML.

Step 4: Write the Activity code

- Open the Activity Java file (e.g., "MyActivity.java").

- Extend the AppCompatActivity class.

- Override the onCreate() method to inflate the layout and initialize UI elements.

Example code:

import androidx.appcompat.app.AppCompatActivity;

import android.os.Bundle;

import android.widget.Button;

import android.widget.TextView;

public class MyActivity extends AppCompatActivity {

@Override

protected void onCreate(Bundle savedInstanceState) {

super.onCreate(savedInstanceState);

setContentView(R.layout.activity_my);

// Initialize UI elements

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


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

Step 5: Declare the Activity in the AndroidManifest.xml

- Open the AndroidManifest.xml file.

- Add the Activity declaration inside the <application> tag:

<activity android:name=".MyActivity"></activity>

Step 6: Run the application

- Connect an Android device or emulator.

- Run the application using the "Run" button or Shift+F10.


In Android development, Views are the basic building blocks of a user interface (UI), responsible for drawing and handling user
interactions. They are rectangular areas on the screen that display content or respond to user input.

Key Concepts:
 View as a Rectangle:
Every View occupies a rectangular area on the screen, even if the content doesn't fill the entire space.
 Superclass:
The android.view.View class is the base class for all UI components in Android.
 Widgets:
Views are often referred to as "widgets" because they represent the visible and interactive elements of the UI.
 Layout Parameters:
Views have layout parameters (like LayoutParams) that define their desired size and position within their parent container.
 Measuring and Drawing:
Views go through a "measure" pass to determine their size based on layout parameters and content, and then a "draw" pass to render themselves
on the screen.
 Event Handling:
Views are responsible for handling user input events like clicks, touches, and key presses.
Using Views:
In Android, a View is a user interface component that represents a rectangular area of the screen. Views
are the basic building blocks of an Android application's user interface.

Here are some common types of Views in Android:

1. Text View

Displays text to the user.

2. Edit Text

Allows the user to enter text.

3. Button

A clickable button that can perform an action.

4. Image View

Displays an image.

5. List View

Displays a list of items.

6. Grid View

Displays a grid of items.

7. Recycler View

A more efficient and flexible version of ListView.

8. CheckBox
A checkbox that can be checked or unchecked.

9. Radio Button

A radio button that can be selected.

10. Spinner

A dropdown list of items.

11. ProgressBar

Displays a progress bar.

12. SeekBar

A slider that allows the user to select a value.

13. Rating Bar

A rating system that allows the user to rate something.

14. Web View

Displays a web page.

15. Surface View

A View that provides a dedicated drawing surface.

16. View Flipper

A View that can flip between multiple child Views.

17. View Switcher

A View that can switch between multiple child Views.

18. Linear Layout

A layout that arranges its child Views in a linear fashion.

19. Relative Layout

A layout that arranges its child Views relative to each other.

20. Constraint Layout

A layout that arranges its child Views using constraints.

These are just some of the many Views available in Android.

Each View has its own set of attributes and methods that can be used to customize its appearance and
behavior.
Layouts in Android SDK
Layout Managers (or simply layouts) are said to be extensions of the ViewGroup class.
They are used to set the position of child Views within the UI we are building. We can nest the
layouts, and therefore we can create arbitrarily complex UIs using a combination of layouts.
There is a number of layout classes in the Android SDK. They can be used, modified or
can create your own to make the UI for your Views, Fragments and Activities. You can display
your contents effectively by using the right combination of layouts.
Types of Layouts
1. Constraint Layout
Constraint Layout is a flexible layout that allows views to be positioned using
constraints instead of nesting layouts. It helps in reducing the view hierarchy and improves
performance by a lot. It is the most popular and recommended layout for designing complex
interfaces in modern Android applications.

2. Linear Layout
A Linear Layout aligns each of the view in a single direction either a vertical or
a horizontal manner. A layout in vertical manner has a single column of views, whereas in a
layout in horizontal manner, has a single row of views. It supports a weight attribute for each
view that can control the relative size of each view within the available space. However,
excessive nesting of Linear Layouts can lead to performance issues, so it’s best for
straightforward layouts with a few elements.

3. Frame Layout
Frame Layout is a simple layout mainly used to hold a single child view, though multiple views
can be stacked on top of each other. It is commonly used for overlays, fragments, and simple UI
components like image views.

4. Relative Layout
Relative layout allows views to be relative to one another or to the parent layout. This
makes positioning flexible as we can position views to the left, right, top, or bottom of other
views. However after Constraint Layout was introduced, the use of Relative Layout has ceased
since Constraint Layout is much better as handling large UIs.

5. Table Layout
Table Layout
arranges views in a
grid-like format using
rows and columns,
similar to an HTML
table. It is useful for
displaying structured
data, such as forms or
spreadsheets. Each
row consists of multiple TableRow elements, and views within rows can be assigned specific
column spans.
6. Grid Layout
Introduced in Android 4.0 (API level 14), the GridLayout is an advanced and more
flexible alternative to TableLayout. It divides the screen into a matrix of rows and columns,
allowing precise placement of elements without needing of nested layouts. It is efficient for
creating grid-based UIs like image galleries or dashboards.

7. Coordinator Layout
Coordinator Layout is an advance layout that provides motion and interactive capabilities
between views. It is mostly used for implementing components like the Collapsing Toolbars, and
swipe-to-dismiss behavior. It allows views to work based on user actions, such as scrolling,
swipe gestures and animations.

You might also like