The View class is a fundamental building block of the Android user interface (UI). It serves as the superclass for various GUI components, including TextView, ImageView, and Button. Here are some key points about View:
- Definition: A View represents a rectangular area on the screen that displays content, such as text, images, or buttons. Although the rectangle is invisible, each View occupies a specific space. The size of this rectangle can be set manually or using predefined values:
a. match_parent: Occupies the entire available space on the device display.
b. wrap_content: Occupies only the necessary space for its content to display. - Attributes: When defining a View in XML, you’ll use attributes to specify how it should appear on the screen. Two essential attributes are:
a. android:layout_height: Determines the height of the View.
b. android:layout_width: Sets the width of the View. - Widgets: Any visual and interactive element visible on the screen is called a Widget. Views are also known as widgets in Android.
- XML Syntax: To create a View, you’ll define it in XML files. The format for each View is as follows:
<ViewName
Attribute1="Value1"
Attribute2="Value2"
...
AttributeN="ValueN" />
Replace ViewName with the specific View type (e.g., TextView, ImageView). Attributes control the appearance and behavior of the View.
Example:
<TextView
android:id="@+id/text_view_id"
android:layout_height="wrap_content"
android:layout_width="wrap_content"
android:text="@string/hello" />
More: https://developer.android.com/reference/android/view/View
This project is a simple implementation of RecyclerView to introduce View classes that commonly used in Android Development.