‫Hello, my friends, and welcome back.
‫In this section, we'll learn about the fragments in Android.
‫Imagine you are building a house with Lego bricks.
‫Each Lego brick is a small piece of your house.
‫Like a room or a part of a room.
‫Fragments in Android are a bit like these Lego bricks for building your application.
‫A fragment represents a reusable portion of your app's user interface.
‫A fragment defines and manages its own layout, has its own life cycle, and can handle its own input
‫events.
‫Fragments can't live on their own.
‫They must be hosted by an activity or another fragment.
‫Fragments are used to create a part of the user interface that can be combined with other fragments
‫to build a complete user experience.
‫They are particularly valuable for developing apps that need to work on various screen sizes, orientations
‫and devices.
‫For example, we have two devices here the tablet with a larger screen and the small screen for the
‫mobile.
‫Let's start with the mobile.
‫Many apps have a bottom navigation bar like this Buttons.
‫So any click on these buttons will lead to change this display.
‫This is a fragment and this is the button.
‫When the user clicks on any of these buttons, the view or the fragment would be changed.
‫And this is a very good example of using the fragments in Android mobile applications for the large
‫screen.
‫We have this activity or this part.
‫This is called activity navigation UI, and we have this part in green that it is the fragment UI.
‫So when the user clicks on any of these buttons or any of these destinations, the fragment UI here
‫will be changed.
‫So this is called the modular user interface Fragments allow you to break your app's user interface
‫into smaller reusable modules.
‫Each fragment represents a specific part of the UI, such as a screen or a portion of a screen, and
‫the fragments are especially important for creating responsive applications.
‫They allow you to adapt your UI to various screen sizes, orientations and different devices.
‫Also, you can combine multiple fragments within a single activity to create complex user interfaces.
‫For example, on the tablet you have two fragments side by side.
‫This is the first fragment and this is the second fragment providing a multi pan layout, whereas on
‫phone you may stack them vertically or like this, in this case a single pan layout.