What is Android View?

A View is a simple building block of a user interface. It is a small rectangular box that can be TextView, EditText, or even a button. It occupies the area on the screen in a rectangular area and is responsible for drawing and event handling. View is a superclass of all the graphical user interface components.

Why and How to use the View in Android?

Now you might be thinking what is the use of a View. So, the use of a view is to draw content on the screen of the user’s Android device. A view can be easily implemented in an Application using the java code. Its creation is more easy in the XML layout file of the project. Like, the project for hello world that we had made initially.

If you have not tried it, refer DataFlair hello world app in Android.

Types of Android Views

Another thing that might now come to your mind must be, “what are the available types of view in Android that we can use?”

For that, we’ll see all these types one by one as follows:

  • TextView
  • EditText
  • Button
  • Image Button
  • Date Picker
  • RadioButton
  • CheckBox buttons
  • Image View

And there are some more components. Learn more about Android UI Controls.

Another important feature in Android is ViewGroup which is as follows.

What is Android View Group?

A View Group is a subclass of the ViewClass and can be considered as a superclass of Layouts. It provides an invisible container to hold the views or layouts. ViewGroup instances and views work together as a container for Layouts. To understand in simpler words it can be understood as a special view that can hold other views that are often known as a child view.

Following are certain commonly used subclasses for ViewGroup:

  • LinearLayout
  • RelativeLayout
  • FrameLayout
  • GridView
  • ListView

Here is how Views and ViewGroups are linked:

Android Views and Viewgroups

Now we’ll move towards the Android layouts:

What is Android Layout?

Layout basically refers to the arrangement of elements on a page these elements are likely to be images, texts or styles. These are a part of Android Jetpack. They define the structure of android user interface in the app, like in an activity. All elements in the layout are built with the help of Views and ViewGroups. These layouts can have various widgets like buttons, labels, textboxes, and many others.

We can define a Layout as follows:

<?xml version="1.0" encoding="utf-8"?> 
  <LinearLayout
       android:id="@+id/layout2"
       android:layout_width="match_parent"
       android:layout_height="match_parent"
       android:layout_weight="1"
       android:background="#8ED3EB"
       android:gravity="center"
       android:orientation="vertical" >
       <TextView
           android:id="@+id/textView4"
           android:layout_width="match_parent"
           android:layout_height="wrap_content"
           android:layout_marginLeft="10dp"
           android:layout_marginTop="-40dp"
           android:fontFamily="@font/almendra_bold"
           android:text="This is a TextView" />
  </LinearLayout>

#android tutorials #android layout #android views

Android Layout and Views - Types and Examples
3.25 GEEK