Android Views

Let's know about Android views

Android Development
Author_1

Ashwini Kumar

Nov. 7, 2022    Views: 113

Android Views

The main building block for the user interface (UI) of an app like the video player you are preparing to develop is creating a View.

What are Views?

The View object is created from the View class and occupies a rectangular screen area. It is responsible for the processing of drawings and events.

The View is the base class for widgets that are used to create interactive components of the user UI such as buttons or text fields.

In summary, a View can be considered a rectangle on the screen that displays a certain type of content, like an image, a piece of text or even a button!

In Android, Views are one of the most important building block of the UI(User Interface) as it contains all the components related to the User Interface. Which contain how the app will look.

Most used Android Views

Some of the most used Android Views include:

  • TextView
  • EditText
  • Button
  • ImageView
  • ImageButton
  • CheckBox
  • RadioButton
  • RecyclerView
  • DatePicker and
  • Spinner

View sizes

A View occupies a rectangle shape, although the rectangle is invisible.

The size of this rectangle can be manually set by specifying the exact size (with appropriate units) or using some predetermined values. These predefined values are match_parent and wrap_content.

match_parent means it will occupy all of the available space available within its parent ViewGroup, whereas wrap_content means it will occupy only as much space as required for its content to display.

XML syntax for creating a View

Now, as you learned previously, to draw anything in your Android application you need to specify it in the design XML files. You will create Kotlin files to add functionality.

Every View in XML has the following format:

<ViewName

    Attribute1=Value1

    Attribute2=Value2

    Attribute3=Value3

    AttributeN=ValueN

/>

 

It always starts with an angle bracket, followed by the View name.

  • You then write attributes that will determine what this view will look like on the app screen along with a value for the attribute. Each view has its own unique attributes.
  • In the end, it is closed by a forward slash and an angle bracket.

So, every View subclass needs to follow this standard so that it can display on the screen of the app. This format is the default standard of XML.

Take note that there are two attributes that are required for every View. These are android:layout_height and android:layout_width.

These attributes determine the size of the invisible rectangle created by the view. Using these attributes, you control the size of every view in your Android app.

Recommanded Articles
SEO by BitGeekTalks

Let's learn about SEO.

SEO is a well-known practice that are been added to a website to make Google know more about our services and know what does your website provides for a user. In simple words, we can say that SEO i

Backlinks

Backlinks and how to create backlinks

What is a Backlink?

In today's digital world data is gold and these data are been abstracted from the other websites to provide a user the content they are searchin

SEO tools

Top six SEO tools

Let see what are the various tools that are been used to improve the rank of a website to rank in search engines and get traffic over the website.

Now, we are gonna see 6 tools that are v

SEO and keywords - BitGeekTalks

What is SEO and Keywords in SEO?

SEO stands for Search engine optimization. It's a processing to give an upper hand on other websites that let the website be on the top of other websites that provide the same service by provid

TemplateDoesNotExit error: BitGeekTalks

TemplateDoesNotExit error in Django

While going through the development of a Django web app we go through the various commands such as django-admin startproject myproject, django-admin startapp my app, etc. After performing the basic