View Group

Responsive image
0 Comments         3217 Views

What is View?

A view is a small rectangular box that responds to user inputs.View is a basic building block of UI (User Interface) in android.Eg: EditText, Button, CheckBox, etc.
The View class is the base class or we can say that it is the superclass for all the GUI components in android.

What is View Group?

The ViewGroup class is a subclass of the View class. And also it will act as a base class for layouts and layouts parameters. The ViewGroup will provide an invisible container to hold other Views or ViewGroups and to define the layout properties. For example, Linear Layout is the ViewGroup that contains UI controls like Button, TextView, etc.

Type of View Group?

Those are the commonly used ViewGroup subclasses used in android applications.

  1. FrameLayout
  2. LinearLayout
  3. RelativeLayout
  4. TableLayout
  5. Constraint Layout
  6. Coordinate Layout
  7. Recycler view

Most used Layouts are Linear Layout, Relative Layout and Constraint Layout. Let's have a discussion about those Layout.

Linear Layout: Linear Layout is the most basic layout in android studio, that aligns all the children sequentially either in a horizontal manner or a vertical manner by specifying the android:orientation attribute.

Relative Layout: Relative Layout is a ViewGroup subclass, used to specify the position of child View elements relative to each other like (A to the right of B) or relative to the parent.

Constraint Layout: Constraint Layout is a combination of Linear Layout, Relative Layout and also some Layout. This layout takes attribute from different Layout.

Table Layout: Android TableLayout is a ViewGroup subclass which is used to display the child View elements in rows and columns. It will arrange all the children elements into rows and columns and does not display any border lines in between rows, columns or cells.

Coordinator Layout: To handle the views in a better way, Android introduced a new layout called the Coordinator Layout. By using Coordinator layout you can easily handle and animate the transitions of views present in a Coordinator Layout.

When the view that is having some motion, the best case is to use the CoordinatorLayout.

Frame Layout: FrameLayout is designed to block out an area on the screen to display a single item. Generally, Frame Layout should be used to hold a single child view, because it can be difficult to organize child views in a way that's scalable to different screen sizes without the children overlapping each other.

Recycler View: When an item scrolls off the screen, recycler view doesn't destroy the view, it reuses the view for new items that have scrolled in screen.

Advantages of using ConstraintLayout in Android

  1. ConstraintLayout provides you the ability to completely design your UI with the drag and drop feature provided by the Android Studio design editor.
  2. It helps to improve the UI performance over other layouts.
  3. With the help of ConstraintLayout, we can control the group of widgets through a single line of code.
  4. With the help of ConstraintLayout, we can easily add animations to the UI components which we used in our app.

Disadvantages of using ConstraintLayout

  1. When we use the Constraint Layout in our app, the XML code generated becomes a bit difficult to understand.
  2. In most of the cases, the result obtain will not be the same as we got to see in the design editor.
  3. Sometimes we have to create a separate layout file for handling the UI for the landscape mode.