View and ViewGroup
•View and ViewGroup are the foundational blocks of Android UI.
• Views are individual UI widgets, while ViewGroups serve as
containers to arrange these widgets.
• A View is the core building block of Android UI – a rectangular area
on the screen responsible for drawing and handling user interaction.
• Examples include: TextView, Button, EditText, ImageView, CheckBox,
RadioButton, ProgressBar, Spinner, etc.
3.
ViewGroup
• A ViewGroupis a specialized View that can contain other Views (and
even other ViewGroups), acting as an invisible container defining
layout structure.
• Common ViewGroup types include:
• LinearLayout – stacks children horizontally or vertically
• RelativeLayout, ConstraintLayout, FrameLayout, TableLayout,
GridView, ListView, WebView
4.
Aspect View ViewGroup
DefinitionA UI component/widget (e.g.,
Button)
A container/layout that holds
View(s) or ViewGroup(s)
Class Hierarchy Inherits from android.view.View Inherits from
android.view.ViewGroup
Purpose Displays content and handles input
Arranges children and manages
layout
Examples TextView, Button, ImageView, etc.
LinearLayout, FrameLayout,
ConstraintLayout, etc.
5.
Building UI –View Hierarchy
• Android UIs are structured as a hierarchy (a tree) of Views and
ViewGroups.
• Each screen has a root ViewGroup, nesting views and other
containers.
• XML is commonly used to declare these hierarchies; Android Studio's
Layout Editor can visually assist.
link an Activityto its layout using:
setContentView(R.layout.activity_main)
Navigation between screens
•To move from one Activity (screen) to another, you use an Intent.
val intent = Intent(this, LoginActivity::class.java)
startActivity(intent)
Why do we use Intents?
•An Intent is like a message you send in Android.
•It tells the system: “Hey, I want to go from this screen to that screen.”
•When you call startActivity(intent), Android looks at the Intent and opens the
Activity you asked for.
•::class.java is Kotlin’s way of saying: “give me the Java Class object of
LoginActivity”.